Is there a way to have the test profile be automatically activated for all tests in Spring Boot? I don't want to depend on class annotations or command line arguments as both are error-prone.
Spring Boot provides a @SpringBootTest annotation, which can be used as an alternative to the standard spring-test @ContextConfiguration annotation when you need Spring Boot features. The annotation works by creating the ApplicationContext used in your tests through SpringApplication .
The default profile is called default ; all the beans that do not have a profile set belong to this profile. There are plenty of ways of defining active profiles in Spring Boot, including command line arguments, Maven settings, JVM system parameters, environment variables, spring. profiles.
@ContextConfiguration defines class-level metadata that is used to determine how to load and configure an ApplicationContext for integration tests.
Yes, you can create application properties files in test/resources directory.
Just create /src/test/resources/application.properties
or /src/test/resources/application.yml
file contains
spring.profiles.active=test
This application.*
file wil be used only in testing.
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