Skip to content

Commit

Permalink
GEODE-4181: Add JUnit 5 Support (apache#6740)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
demery-pivotal authored Aug 5, 2021
1 parent f7cc081 commit d58482b
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 7 deletions.
20 changes: 20 additions & 0 deletions boms/geode-all-bom/src/test/resources/expected-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,26 @@
<artifactId>hamcrest</artifactId>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions extensions/geode-modules/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
2 changes: 2 additions & 0 deletions geode-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
1 change: 1 addition & 0 deletions geode-concurrency-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions geode-jmh/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
5 changes: 5 additions & 0 deletions geode-junit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
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 {
Expand Down Expand Up @@ -398,7 +398,7 @@ public void repeatUntilValue_throwsIfValueIsNeverTrue(Execution execution) {
.repeatForDuration(Duration.ofSeconds(2));

assertThatThrownBy(() -> execution.execute(concurrencyRule))
.isInstanceOf(ComparisonFailure.class);
.isInstanceOf(AssertionFailedError.class);
assertThat(invoked.get()).isTrue();
}

Expand Down Expand Up @@ -518,8 +518,8 @@ public void runManyThreads(Execution execution) {
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);
}
Expand Down
21 changes: 20 additions & 1 deletion geode-junit/src/test/resources/expected-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
</exclusion>
</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>
Expand Down Expand Up @@ -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>
1 change: 1 addition & 0 deletions geode-rebalancer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
6 changes: 4 additions & 2 deletions gradle/test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ compileTestJava {
}

test {
useJUnitPlatform {}
doFirst {
TestPropertiesWriter.writeTestProperties(buildDir, name)
}
Expand Down Expand Up @@ -91,7 +92,7 @@ configure([integrationTest, distributedTest, performanceTest, acceptanceTest, ui
}

configure([integrationTest, distributedTest, performanceTest]) {
useJUnit {
useJUnitPlatform {
if (project.hasProperty("testCategory")) {
includeCategories += project.testCategory
}
Expand Down Expand Up @@ -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(',')
}
Expand All @@ -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")) {
Expand Down
1 change: 1 addition & 0 deletions static-analysis/pmd-rules/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}

0 comments on commit d58482b

Please sign in to comment.