From 0b552a3534e080ca842c7f08a9950233ce56e72e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 15 Sep 2021 14:15:59 +0200 Subject: [PATCH] Migrate to TestNG Engine for the JUnit Platform in spring-test Prior to this commit, we had configured separate test tasks for JUnit and TestNG. In addition, we configured a standard `test` task that depended on the `junit` and `testNG` tasks, and we had an additional `aggregateTestReports` task that aggregated the reports from the JUnit and TestNG test tasks. Thanks to the introduction of the "TestNG Engine for the JUnit Platform", this commit simplifies our Gradle build in the spring-test module by running JUnit 4, JUnit Jupiter, and TestNG tests on the JUnit Platform in a single Gradle `test` task. See gh-27406 --- build.gradle | 1 + spring-test/spring-test.gradle | 34 +++++++--------------------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/build.gradle b/build.gradle index 8a3207ccc85..e5913130731 100644 --- a/build.gradle +++ b/build.gradle @@ -188,6 +188,7 @@ configure(allprojects) { project -> exclude group: "junit", name: "junit" } dependency "org.testng:testng:7.4.0" + dependency "org.junit.support:testng-engine:1.0.1" dependency "org.hamcrest:hamcrest:2.1" dependency "org.awaitility:awaitility:3.1.6" dependency "org.assertj:assertj-core:3.20.2" diff --git a/spring-test/spring-test.gradle b/spring-test/spring-test.gradle index 365ce7d316f..026507a0281 100644 --- a/spring-test/spring-test.gradle +++ b/spring-test/spring-test.gradle @@ -77,43 +77,23 @@ dependencies { testRuntimeOnly("org.junit.vintage:junit-vintage-engine") { exclude group: "junit", module: "junit" } + testRuntimeOnly("org.junit.support:testng-engine") testRuntimeOnly("org.glassfish:javax.el") testRuntimeOnly("com.sun.xml.bind:jaxb-core") testRuntimeOnly("com.sun.xml.bind:jaxb-impl") } -task junit(type: Test) { - description = "Runs JUnit 4 and JUnit Jupiter tests." +test { + description = "Runs JUnit 4, JUnit Jupiter, and TestNG tests." useJUnitPlatform { + includeEngines "junit-vintage", "junit-jupiter", "testng" excludeTags "failing-test-case" } + // We use `include` instead of `filter.includeTestsMatching`, since + // the latter results in some tests being executed/reported + // multiple times. include(["**/*Tests.class", "**/*Test.class"]) - exclude(["**/testng/**/*.*"]) systemProperty("testGroups", project.properties.get("testGroups")) // Java Util Logging for the JUnit Platform. // systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager") } - -task testNG(type: Test) { - description = "Runs TestNG tests." - useTestNG() - include(["**/testng/**/*Tests.class", "**/testng/**/*Test.class"]) - systemProperty("testGroups", project.properties.get("testGroups")) - // Show STD_OUT & STD_ERR of the test JVM(s) on the console: - // testLogging.showStandardStreams = true - // forkEvery 1 -} - -test { - description = "Runs all tests." - dependsOn junit, testNG - exclude(["**/*.*"]) -} - -task aggregateTestReports(type: TestReport) { - description = "Aggregates JUnit and TestNG test reports." - destinationDir = test.reports.html.outputLocation.get().getAsFile() - reportOn junit, testNG -} - -check.dependsOn aggregateTestReports