diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml index bb7d54218a..8a76dc903c 100644 --- a/testing-modules/spring-testing/pom.xml +++ b/testing-modules/spring-testing/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.baeldung spring-testing @@ -21,7 +22,7 @@ ${hamcrest.version} - + org.projectlombok lombok ${lombok.version} @@ -33,7 +34,7 @@ spring-boot-starter LATEST - + org.springframework.boot @@ -52,7 +53,7 @@ LATEST - org.springframework + org.springframework spring-webmvc ${spring.version} @@ -72,6 +73,17 @@ ${junit.jupiter.version} test + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + org.awaitility awaitility diff --git a/testing-modules/spring-testing/src/test/java/com/baeldung/dirtiescontext/DirtiesContextIntegrationTest.java b/testing-modules/spring-testing/src/test/java/com/baeldung/dirtiescontext/DirtiesContextIntegrationTest.java index 7fad754b8f..f3e7b8c228 100644 --- a/testing-modules/spring-testing/src/test/java/com/baeldung/dirtiescontext/DirtiesContextIntegrationTest.java +++ b/testing-modules/spring-testing/src/test/java/com/baeldung/dirtiescontext/DirtiesContextIntegrationTest.java @@ -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"); } }