Is there any way to make Spring boot use a completely fresh ApplicationContext on every single @Test method execution and discard the previous application context ?
Anyway to change the default behavior of reusing ApplicationContext ?
Is there any way to make Spring boot use a completely fresh ApplicationContext on every single @Test method execution and discard the previous application context ?
Anyway to change the default behavior of reusing ApplicationContext ?
You can annotate a test method with @DirtiesContext to indicate the ApplicationContext after running this test method is dirty such that when it executes the next test method , it will completely refresh the ApplicationContext :
@SpringBootTest
public class FooTest {
@Test
@DirtiesContext
public void test1() {
}
@Test
@DirtiesContext
public void test2() {
}
}