how to run/turn off selective tests based on profiles in spring boot
You would want to use the @IfProfileValue
annotation. Unfortunately it doesn't work directly on the active profiles but it can read a property so if you only define a specific property within the profiles that you want to run the test on then you can use that annotation on that specific property.
It works also with active profiles - there is a property value containing active profiles:
Test only active with specific profile:
@IfProfileValue(name = "spring.profiles.active", values = {"specific"})
Since i have tests that should NOT run if specific profile is active i added this to those tests:
@ActiveProfiles(profiles = {"default"})
It does not work with @IfProfileValue
and "default" and i also didn't found any "run if specific profile is not active.
In Spring you can also use the @DisabledIf
annotation. It allows for specifying a Spring Expression Language expression. See this blog post for examples.
JUnit 5 also has:
@DisabledIfEnvironmentVariable
@DisabledIfSystemProperty