@ContextConfiguration location attribute does not make sense for Spring Boot integration testing. Is there any other way for reusing application context across multiple test classes annotated with @SpringBootTest ?
@ContextConfiguration location attribute does not make sense for Spring Boot integration testing. Is there any other way for reusing application context across multiple test classes annotated with @SpringBootTest ?
For those like me landing from Google:
If you have <reuseFork>false</reuseFork> in your Maven surefire plugin, there is no chance your context can be reused, as you're effectively spawning a new JVM for each test class.
This is well documented in Spring Documentation: https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#testcontext-ctx-management-caching
If you land here from Google and have an issue with multiple application contexts being started, also take note of this:
Make sure that when you use @SpringBootTests multiple times that you use the same properties.
E.g. if you have one test using simply @SpringBootTest and another one using @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) each will spin up its own context!
Easiest would be to have a BaseIntegrationTest class which you extend in every integration test and put the @SpringBootTest annotation on that base class, e.g.:
package com.example.demo;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public abstract class BaseIntegrationTest{
}