Spring-boot utilizes Spring profiles (http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html) which allow for instance to have separate co
Another programatically way to do that:
import static org.springframework.core.env.AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME;
@BeforeClass
public static void setupTest() {
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "test");
}
It works great.
If you simply want to set/use default profile at the time of making build through maven then, pass the argument
-Dspring.profiles.active=test
Just like
mvn clean install -Dspring.profiles.active=dev
As far as I know there is nothing directly addressing your request - but I can suggest a proposal that could help:
You could use your own test annotation that is a meta annotation comprising @SpringBootTest
and @ActiveProfiles("test")
. So you still need the dedicated profile but avoid scattering the profile definition across all your test.
This annotation will default to the profile test
and you can override the profile using the meta annotation.
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@SpringBootTest
@ActiveProfiles
public @interface MyApplicationTest {
@AliasFor(annotation = ActiveProfiles.class, attribute = "profiles") String[] activeProfiles() default {"test"};
}
You could put an application.properties file in your test/resources folder. There you set
spring.profiles.active=test
This is kind of a default test profile while running tests.
You can put your test specific properties into src/test/resources/config/application.properties
.
The properties defined in this file will override those defined in src/main/resources/application.properties
during testing.
For more information on why this works have a look at Spring Boots docs.