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() {
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.