You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by dh...@apache.org on 2021/08/05 22:29:54 UTC

[geode] branch develop updated: GEODE-4181: Add JUnit 5 Support (#6740)

This is an automated email from the ASF dual-hosted git repository.

dhemery pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new d58482b  GEODE-4181: Add JUnit 5 Support (#6740)
d58482b is described below

commit d58482bed05e70eb848c9586df173d54e55193e5
Author: Dale Emery <de...@vmware.com>
AuthorDate: Thu Aug 5 15:28:42 2021 -0700

    GEODE-4181: Add JUnit 5 Support (#6740)
    
    Added JUnit 5 support to all Geode projects that use `geode-junit`.
    
    STANDARD TEST TASKS
    
    Updated **./gradle/test.gradle** to configure these standard test tasks
    to use JUnit Platform to run tests:
    - `test` and `repeatUnitTest`
    - `acceptanceTest` and `repeatAcceptanceTest`
    - `distributedTest` and `repeatDistributedTest`
    - `integrationTest` and `repeatIntegrationTest`
    - `performanceTest`
    - `uiTest`
    - `upgradeTest` and `repeatUpgradeTest`
    
    STANDARD TEST MODULES
    
    Updated **./geode-junit/build.gradle**:
    - Added `junit-jupiter-api` and `junit-jupiter-params` as API
      dependencies.
    - Added `junit-jupiter-engine` and `junit-vintage-engine` as
      implementation dependencies.
    
    These changes add JUnit 5 support to any source set that depends on
    `geode-junit`, either directly or via `geode-dunit`.
    
    OTHER PROJECTS
    
    Added `junit-vintage-engine` dependency directly to each project that
    runs tests without `geode-junit` or `geode-dunit`:
    - `geode-common`
    - `geode-concurrency-test`
    - `geode-jmh`
    - `geode-modules`
    - `geode-rebalancer`
    - `static-analysis:pmd-rules`
    
    These changes **do not** add JUnit 5 support to these projects.
    Developers who want JUnit 5 support in these projects can declare
    dependencies on `junit-jupiter-api`, `junit-jupiter-params`, and
    `junit-jupiter-engine`.
    
    SPECIFIC TESTS
    
    Change `ConcurrencyRuleTest` to expect the exception types and exception
    messages thrown by AssertJ when `opentest4j` is on the classpath.
---
 .../src/test/resources/expected-pom.xml             | 20 ++++++++++++++++++++
 .../gradle/plugins/DependencyConstraints.groovy     | 11 +++++++++++
 extensions/geode-modules/build.gradle               |  1 +
 geode-common/build.gradle                           |  2 ++
 geode-concurrency-test/build.gradle                 |  1 +
 geode-jmh/build.gradle                              |  1 +
 geode-junit/build.gradle                            |  5 +++++
 .../geode/test/junit/rules/ConcurrencyRuleTest.java |  8 ++++----
 geode-junit/src/test/resources/expected-pom.xml     | 21 ++++++++++++++++++++-
 geode-rebalancer/build.gradle                       |  1 +
 gradle/test.gradle                                  |  6 ++++--
 static-analysis/pmd-rules/build.gradle              |  1 +
 12 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/boms/geode-all-bom/src/test/resources/expected-pom.xml b/boms/geode-all-bom/src/test/resources/expected-pom.xml
index 01d6a20..bb0a4e6 100644
--- a/boms/geode-all-bom/src/test/resources/expected-pom.xml
+++ b/boms/geode-all-bom/src/test/resources/expected-pom.xml
@@ -583,6 +583,26 @@
         <version>2.2</version>
       </dependency>
       <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-api</artifactId>
+        <version>5.7.2</version>
+      </dependency>
+      <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-params</artifactId>
+        <version>5.7.2</version>
+      </dependency>
+      <dependency>
+        <groupId>org.junit.jupiter</groupId>
+        <artifactId>junit-jupiter-engine</artifactId>
+        <version>5.7.2</version>
+      </dependency>
+      <dependency>
+        <groupId>org.junit.vintage</groupId>
+        <artifactId>junit-vintage-engine</artifactId>
+        <version>5.7.2</version>
+      </dependency>
+      <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-api</artifactId>
         <version>3.141.59</version>
diff --git a/buildSrc/src/main/groovy/org/apache/geode/gradle/plugins/DependencyConstraints.groovy b/buildSrc/src/main/groovy/org/apache/geode/gradle/plugins/DependencyConstraints.groovy
index a9876a4..7b37766 100644
--- a/buildSrc/src/main/groovy/org/apache/geode/gradle/plugins/DependencyConstraints.groovy
+++ b/buildSrc/src/main/groovy/org/apache/geode/gradle/plugins/DependencyConstraints.groovy
@@ -65,6 +65,7 @@ class DependencyConstraints implements Plugin<Project> {
 
     // These versions are referenced in test.gradle, which is aggressively injected into all projects.
     deps.put("junit.version", "4.13.2")
+    deps.put("junit-jupiter.version", "5.7.2")
     deps.put("cglib.version", "3.3.0")
     return deps
   }
@@ -221,6 +222,16 @@ class DependencyConstraints implements Plugin<Project> {
       entry('hamcrest')
     }
 
+    dependencySet(group: 'org.junit.jupiter', version: get('junit-jupiter.version')) {
+      entry('junit-jupiter-api')
+      entry('junit-jupiter-params')
+      entry('junit-jupiter-engine')
+    }
+
+    dependencySet(group: 'org.junit.vintage', version: get('junit-jupiter.version')) {
+      entry('junit-vintage-engine')
+    }
+
     dependencySet(group: 'org.seleniumhq.selenium', version: '3.141.59') {
       entry('selenium-api')
       entry('selenium-chrome-driver')
diff --git a/extensions/geode-modules/build.gradle b/extensions/geode-modules/build.gradle
index 1800cae..806dced 100644
--- a/extensions/geode-modules/build.gradle
+++ b/extensions/geode-modules/build.gradle
@@ -41,6 +41,7 @@ dependencies {
   // test
   testImplementation('org.apache.bcel:bcel')
   testImplementation('junit:junit')
+  testRuntimeOnly('org.junit.vintage:junit-vintage-engine')
   testImplementation('org.assertj:assertj-core')
   testImplementation('org.mockito:mockito-core')
   testImplementation('org.apache.tomcat:catalina-ha:' + DependencyConstraints.get('tomcat6.version'))
diff --git a/geode-common/build.gradle b/geode-common/build.gradle
index 3e9000a..cb48856 100755
--- a/geode-common/build.gradle
+++ b/geode-common/build.gradle
@@ -28,11 +28,13 @@ dependencies {
 
   // test
   testImplementation('junit:junit')
+  testRuntimeOnly('org.junit.vintage:junit-vintage-engine')
   testImplementation('org.assertj:assertj-core')
   testImplementation('org.mockito:mockito-core')
 
 
   // jmhTest
   jmhTestImplementation('junit:junit')
+  jmhTestRuntimeOnly('org.junit.vintage:junit-vintage-engine')
   jmhTestImplementation('org.assertj:assertj-core')
 }
diff --git a/geode-concurrency-test/build.gradle b/geode-concurrency-test/build.gradle
index cb44122..f257bae 100644
--- a/geode-concurrency-test/build.gradle
+++ b/geode-concurrency-test/build.gradle
@@ -25,6 +25,7 @@ dependencies {
   implementation('junit:junit')
   implementation('org.apache.logging.log4j:log4j-api')
   integrationTestImplementation('org.assertj:assertj-core')
+  integrationTestRuntimeOnly('org.junit.vintage:junit-vintage-engine')
 }
 
 integrationTest {
diff --git a/geode-jmh/build.gradle b/geode-jmh/build.gradle
index 37e0284..79b49a1 100644
--- a/geode-jmh/build.gradle
+++ b/geode-jmh/build.gradle
@@ -27,6 +27,7 @@ dependencies {
   api('org.openjdk.jmh:jmh-core')
 
   testImplementation('junit:junit')
+  testRuntimeOnly('org.junit.vintage:junit-vintage-engine')
   testImplementation('org.assertj:assertj-core')
   testImplementation('org.mockito:mockito-core')
 }
diff --git a/geode-junit/build.gradle b/geode-junit/build.gradle
index cc762c2..3f5d17c 100755
--- a/geode-junit/build.gradle
+++ b/geode-junit/build.gradle
@@ -38,6 +38,8 @@ dependencies {
   api('junit:junit') {
     exclude module: 'hamcrest'
   }
+  api('org.junit.jupiter:junit-jupiter-api')
+  api('org.junit.jupiter:junit-jupiter-params')
   api('org.assertj:assertj-core')
   api('org.mockito:mockito-core')
 
@@ -60,6 +62,9 @@ dependencies {
   
   api('org.skyscreamer:jsonassert')
 
+  implementation('org.junit.jupiter:junit-jupiter-engine')
+  implementation('org.junit.vintage:junit-vintage-engine')
+
   testImplementation('pl.pragmatists:JUnitParams')
 
 }
diff --git a/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ConcurrencyRuleTest.java b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ConcurrencyRuleTest.java
index cf2d35f..257526f 100644
--- a/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ConcurrencyRuleTest.java
+++ b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/ConcurrencyRuleTest.java
@@ -33,11 +33,11 @@ import java.util.function.Consumer;
 import junitparams.JUnitParamsRunner;
 import junitparams.Parameters;
 import org.junit.Before;
-import org.junit.ComparisonFailure;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.model.MultipleFailureException;
+import org.opentest4j.AssertionFailedError;
 
 @RunWith(JUnitParamsRunner.class)
 public class ConcurrencyRuleTest {
@@ -398,7 +398,7 @@ public class ConcurrencyRuleTest {
         .repeatForDuration(Duration.ofSeconds(2));
 
     assertThatThrownBy(() -> execution.execute(concurrencyRule))
-        .isInstanceOf(ComparisonFailure.class);
+        .isInstanceOf(AssertionFailedError.class);
     assertThat(invoked.get()).isTrue();
   }
 
@@ -518,8 +518,8 @@ public class ConcurrencyRuleTest {
     assertThat(errors.get(0)).isInstanceOf(AssertionError.class)
         .hasMessageContaining(IOException.class.getName());
     assertThat(errors.get(1)).isInstanceOf(AssertionError.class)
-        .hasMessageContaining("[successful] value")
-        .hasMessageContaining("[wrong] value");
+        .hasMessageContaining("successful value")
+        .hasMessageContaining("wrong value");
     assertThat(errors.get(2)).hasMessageContaining("foo")
         .isInstanceOf(IOException.class);
   }
diff --git a/geode-junit/src/test/resources/expected-pom.xml b/geode-junit/src/test/resources/expected-pom.xml
index f319e20..58918de 100644
--- a/geode-junit/src/test/resources/expected-pom.xml
+++ b/geode-junit/src/test/resources/expected-pom.xml
@@ -58,6 +58,16 @@
       </exclusions>
     </dependency>
     <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-params</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
       <groupId>org.assertj</groupId>
       <artifactId>assertj-core</artifactId>
       <scope>compile</scope>
@@ -138,5 +148,14 @@
       <artifactId>jsonassert</artifactId>
       <scope>compile</scope>
     </dependency>
-  </dependencies>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.junit.vintage</groupId>
+      <artifactId>junit-vintage-engine</artifactId>
+      <scope>runtime</scope>
+    </dependency>  </dependencies>
 </project>
diff --git a/geode-rebalancer/build.gradle b/geode-rebalancer/build.gradle
index e5892d4..96911f1 100644
--- a/geode-rebalancer/build.gradle
+++ b/geode-rebalancer/build.gradle
@@ -38,6 +38,7 @@ dependencies {
   }
 
   testImplementation('junit:junit')
+  testImplementation('org.junit.vintage:junit-vintage-engine')
   testImplementation('org.assertj:assertj-core')
   testImplementation('org.mockito:mockito-core')
 
diff --git a/gradle/test.gradle b/gradle/test.gradle
index 9e31f56..f3f7a25 100644
--- a/gradle/test.gradle
+++ b/gradle/test.gradle
@@ -31,6 +31,7 @@ compileTestJava {
 }
 
 test {
+  useJUnitPlatform {}
   doFirst {
     TestPropertiesWriter.writeTestProperties(buildDir, name)
   }
@@ -91,7 +92,7 @@ configure([integrationTest, distributedTest, performanceTest, acceptanceTest, ui
 }
 
 configure([integrationTest, distributedTest, performanceTest]) {
-  useJUnit {
+  useJUnitPlatform {
     if (project.hasProperty("testCategory")) {
       includeCategories += project.testCategory
     }
@@ -135,6 +136,7 @@ task repeatUnitTest(type: RepeatTest) {
 }
 
 configure([integrationTest, distributedTest, performanceTest, acceptanceTest, uiTest, upgradeTest]) {
+  useJUnitPlatform {}
   if (project.hasProperty('excludeTest')) {
     exclude project.getProperty('excludeTest').split(',')
   }
@@ -143,7 +145,7 @@ configure([integrationTest, distributedTest, performanceTest, acceptanceTest, ui
 configure([repeatDistributedTest, repeatIntegrationTest, repeatUpgradeTest, repeatUnitTest, repeatAcceptanceTest]) {
   times = Integer.parseInt(repeat)
   forkEvery 1
-  useJUnit {}
+  useJUnitPlatform {}
   outputs.upToDateWhen { false }
 
   if (project.hasProperty("failOnNoMatchingTests")) {
diff --git a/static-analysis/pmd-rules/build.gradle b/static-analysis/pmd-rules/build.gradle
index 84f3a95..9484744 100644
--- a/static-analysis/pmd-rules/build.gradle
+++ b/static-analysis/pmd-rules/build.gradle
@@ -20,6 +20,7 @@ apply from: "${rootDir}/${scriptDir}/warnings.gradle"
 
 dependencies {
     implementation(platform(project(':boms:geode-all-bom')))
+    testRuntimeOnly('org.junit.vintage:junit-vintage-engine')
     implementation('net.sourceforge.pmd:pmd-java')
     testImplementation('net.sourceforge.pmd:pmd-test')
 }