Can Spring Boot test classes reuse application context for faster test run?

Viewed 28814

@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 ?

4 Answers

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{
}
Related