2

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 ?

ng.newbie
  • 2,807
  • 3
  • 23
  • 57

1 Answers1

2

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() {

    }

}
Ken Chan
  • 84,777
  • 26
  • 143
  • 172