[BAEL-2998] - Adding example for @DirtiesContext

This commit is contained in:
at508
2019-09-22 22:46:13 -04:00
parent a76bf62420
commit cc827908e0
5 changed files with 102 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
package com.baeldung.dirtiescontext;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.MethodMode;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SpringDataRestApplication.class)
class DirtiesContextTest {
@Autowired
protected UserCache userCache;
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
@Test
void testOne() {
userCache.addUser("John Doe");
userCache.printUserList("Test One");
}
@Test
void testTwo() {
userCache.printUserList("Test Two");
}
@Test
void testThree() {
userCache.addUser("Jane Doe");
userCache.printUserList("Test Three");
}
@Test
void testFour() {
userCache.printUserList("Test Four");
}
}