I have two profiles: dev and default. And I would like to skip some (not all) tests when the active profile is default. Is it possible to mark these tests somehow to do so? Or how can this be achieved? I use springboot. This is my parent test class:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyServiceStarter.class, webEnvironment= SpringBootTest.WebEnvironment.DEFINED_PORT,
properties = {"flyway.locations=filesystem:../database/h2", "server.port=9100", "spring.profiles.default=dev"})
@Category(IntegrationTest.class)
public abstract class AbstractModuleIntegrationTest { ... }
The solution would be to create more property files and add the "profile" name as the suffix and configure Spring Boot to pick the appropriate properties based on the profile. Then, we need to create three application. properties : application-dev.
@SpringBootTest is a primary annotation to create unit and integration tests in Spring Boot applications. The annotation enables additional features such as custom environment properties, different web environment modes, random ports, TestRestTemplate and WebTestClient beans.
If you want to ignore a test method, use @Ignore along with @Test annotation. If you want to ignore all the tests of class, use @Ignore annotation at the class level.
My colleague found a solution:
so if you need to annotate separate tests you can use the @IfProfileValue
annotation:
@IfProfileValue(name ="spring.profiles.active", value ="default")
@Test
public void testSomething() {
//testing logic
}
This test will run only when default profile is active
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With