Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mark springboot tests so they run only when certain profile is active

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 { ... }
like image 401
IKo Avatar asked May 08 '17 15:05

IKo


People also ask

How do I keep my spring boot profiles different?

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.

What does SpringBootTest annotation do?

@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.

How do you ignore test cases in spring boot?

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.


1 Answers

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

like image 141
IKo Avatar answered Sep 24 '22 17:09

IKo