Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test profile for all tests in Spring Boot?

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.

like image 463
pupeno Avatar asked Sep 05 '17 10:09

pupeno


People also ask

What does SpringBootTest annotation do?

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 .

What is the default profile in spring boot?

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.

What is @ContextConfiguration in spring boot?

@ContextConfiguration defines class-level metadata that is used to determine how to load and configure an ApplicationContext for integration tests.


1 Answers

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.

like image 123
Bukharov Sergey Avatar answered Oct 05 '22 19:10

Bukharov Sergey