[BAEL-2998] - ordering and renaming tests for @DirtiesContext example
This commit is contained in:
parent
e25f50fa1b
commit
4881c701fd
|
@ -1,5 +1,6 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.baeldung</groupId>
|
||||
<artifactId>spring-testing</artifactId>
|
||||
|
@ -21,7 +22,7 @@
|
|||
<version>${hamcrest.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
|
@ -33,7 +34,7 @@
|
|||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -52,7 +53,7 @@
|
|||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
@ -72,6 +73,17 @@
|
|||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
package com.baeldung.dirtiescontext;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = SpringDataRestApplication.class)
|
||||
class DirtiesContextIntegrationTest {
|
||||
|
||||
|
@ -19,26 +20,30 @@ class DirtiesContextIntegrationTest {
|
|||
protected UserCache userCache;
|
||||
|
||||
@Test
|
||||
void testA() {
|
||||
@Order(1)
|
||||
void addJaneDoeAndPrintCache() {
|
||||
userCache.addUser("Jane Doe");
|
||||
userCache.printUserList("Test A");
|
||||
userCache.printUserList("addJaneDoeAndPrintCache");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testB() {
|
||||
userCache.printUserList("Test B");
|
||||
@Order(2)
|
||||
void printCache() {
|
||||
userCache.printUserList("printCache");
|
||||
}
|
||||
|
||||
@DirtiesContext(methodMode = MethodMode.AFTER_METHOD)
|
||||
@Test
|
||||
void testC() {
|
||||
@Order(3)
|
||||
void addJohnDoeAndPrintCache() {
|
||||
userCache.addUser("John Doe");
|
||||
userCache.printUserList("Test C");
|
||||
userCache.printUserList("addJohnDoeAndPrintCache");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testD() {
|
||||
userCache.printUserList("Test D");
|
||||
@Order(4)
|
||||
void printCacheAgain() {
|
||||
userCache.printUserList("printCacheAgain");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue