-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add func test for gradle / junit test dry run mode (#201)
* Add func test for gradle / junit test dry run mode * Update gradle distribution to gradle-8.3-20230715071551+0000 in gradle-wrapper.properties --------- Signed-off-by: Jean Gauthier <[email protected]>
- Loading branch information
1 parent
414d60a
commit 108e6f0
Showing
3 changed files
with
178 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionSha256Sum=e111cb9948407e26351227dabce49822fb88c37ee72f1d1582a69c68af2e702f | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
distributionSha256Sum=2d50b3ee9d6b59da48e7f0facda054325498b141b1e5b025a7dff2cd96080497 | ||
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-8.3-20230715071551+0000-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
plugin/src/test/groovy/org/gradle/testretry/TestDryRunFuncTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* Copyright 2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.gradle.testretry | ||
|
||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.util.GradleVersion | ||
|
||
class TestDryRunFuncTest extends AbstractGeneralPluginFuncTest { | ||
|
||
private static final GradleVersion GRADLE_8_3 = GradleVersion.version("8.3") | ||
private static final String MIN_JUPITER_VERSION_DRY_RUN = "5.10.0-RC1" | ||
private static final String MIN_PLATFORM_VERSION_DRY_RUN = "1.10.0-RC1" | ||
|
||
@Override | ||
protected String buildConfiguration() { | ||
return """dependencies { | ||
testImplementation 'org.junit.jupiter:junit-jupiter:$MIN_JUPITER_VERSION_DRY_RUN' | ||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:$MIN_PLATFORM_VERSION_DRY_RUN' | ||
}""" | ||
} | ||
|
||
def "emits skipped test method events if dryRun = true and retry plugin is enabled"() { | ||
given: | ||
def gradle83OrAbove = GradleVersion.version(gradleVersion) >= GRADLE_8_3 | ||
setupTest(gradle83OrAbove, true) | ||
successfulJUnit5Test() | ||
|
||
when: | ||
def result = gradleRunner(gradleVersion).build() | ||
|
||
then: | ||
gradle83OrAbove ? methodSkipped(result) : methodPassed(result) | ||
|
||
where: | ||
gradleVersion << GRADLE_VERSIONS_UNDER_TEST | ||
} | ||
|
||
def "emits skipped test method events when --test-dry-run is used and retry plugin is enabled"() { | ||
given: | ||
def gradle83OrAbove = GradleVersion.version(gradleVersion) >= GRADLE_8_3 | ||
setupTest(gradle83OrAbove, false) | ||
successfulJUnit5Test() | ||
|
||
when: | ||
def result = gradle83OrAbove ? gradleRunner(gradleVersion, 'test', '-S', "--test-dry-run").build() : gradleRunner(gradleVersion).build() | ||
|
||
then: | ||
gradle83OrAbove ? methodSkipped(result) : methodPassed(result) | ||
|
||
where: | ||
gradleVersion << GRADLE_VERSIONS_UNDER_TEST | ||
} | ||
|
||
def "emits skipped test method events, if dryRun is set to true via system properties and retry plugin is enabled"() { | ||
given: | ||
def gradle83OrAbove = GradleVersion.version(gradleVersion) >= GRADLE_8_3 | ||
setupTest(gradle83OrAbove, false, Optional.of(true)) | ||
successfulJUnit5Test() | ||
|
||
when: | ||
def result = gradleRunner(gradleVersion).build() | ||
|
||
then: | ||
gradle83OrAbove ? methodSkipped(result) : methodPassed(result) | ||
|
||
where: | ||
gradleVersion << GRADLE_VERSIONS_UNDER_TEST | ||
} | ||
|
||
def "does not emit skipped test method events when --no-test-dry-run is used and retry plugin is enabled"() { | ||
given: | ||
def gradle83OrAbove = GradleVersion.version(gradleVersion) >= GRADLE_8_3 | ||
setupTest(gradle83OrAbove, false) | ||
successfulJUnit5Test() | ||
|
||
when: | ||
def result = gradle83OrAbove ? gradleRunner(gradleVersion, 'test', '-S', "--no-test-dry-run").build() : gradleRunner(gradleVersion).build() | ||
|
||
then: | ||
methodPassed(result) | ||
|
||
where: | ||
gradleVersion << GRADLE_VERSIONS_UNDER_TEST | ||
} | ||
|
||
def "does not emit skipped test method events, if dryRun is set to false via system properties and retry plugin is enabled"() { | ||
given: | ||
def gradle83OrAbove = GradleVersion.version(gradleVersion) >= GRADLE_8_3 | ||
setupTest(gradle83OrAbove, false, Optional.of(false)) | ||
successfulJUnit5Test() | ||
|
||
when: | ||
def result = gradleRunner(gradleVersion).build() | ||
|
||
then: | ||
methodPassed(result) | ||
|
||
where: | ||
gradleVersion << GRADLE_VERSIONS_UNDER_TEST | ||
} | ||
|
||
def "does not emit skipped test method events by default and retry plugin is enabled"() { | ||
given: | ||
def gradle83OrAbove = GradleVersion.version(gradleVersion) >= GRADLE_8_3 | ||
setupTest(gradle83OrAbove, false) | ||
successfulJUnit5Test() | ||
|
||
when: | ||
def result = gradleRunner(gradleVersion).build() | ||
|
||
then: | ||
methodPassed(result) | ||
|
||
where: | ||
gradleVersion << GRADLE_VERSIONS_UNDER_TEST | ||
} | ||
|
||
private void setupTest(boolean gradle83OrAbove, boolean withTestDryRun) { | ||
setupTest(gradle83OrAbove, withTestDryRun, Optional.empty()) | ||
} | ||
|
||
private void setupTest(boolean gradle83OrAbove, boolean withTestDryRun, Optional<Boolean> withSysPropDryRun) { | ||
buildFile << """ | ||
test { | ||
useJUnitPlatform() | ||
${gradle83OrAbove && withTestDryRun ? "dryRun = true" : ""} | ||
${withSysPropDryRun.map { it -> gradle83OrAbove && it ? "systemProperty('junit.platform.execution.dryRun.enabled', $it)" : "" }.orElse("")} | ||
retry { | ||
maxRetries = 1 | ||
} | ||
} | ||
""" | ||
} | ||
|
||
private void successfulJUnit5Test() { | ||
writeTestSource """ | ||
package acme; | ||
public class SuccessfulTests { | ||
@org.junit.jupiter.api.Test | ||
public void successTest() {} | ||
} | ||
""" | ||
} | ||
|
||
private static boolean methodPassed(BuildResult result) { | ||
return result.output.count('PASSED') == 1 | ||
} | ||
|
||
private static boolean methodSkipped(BuildResult result) { | ||
return result.output.count('SKIPPED') == 1 | ||
} | ||
} |