Skip to content

Commit

Permalink
Adapt tests for JUnit vintage with older Gradle versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaley committed Jun 2, 2020
1 parent b68705d commit d5ea91e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class JUnit4FuncTest extends AbstractPluginFuncTest {
false
}

protected String initializationErrorSyntheticTestMethodName(String gradleVersion) {
"initializationError"
}

@Unroll
def "handles failure in #lifecycle (gradle version #gradleVersion)"() {
given:
Expand Down Expand Up @@ -205,7 +209,7 @@ class JUnit4FuncTest extends AbstractPluginFuncTest {
def result = gradleRunner(gradleVersion).build()
then:
result.output.count('FlakyTests > initializationError FAILED') == 1
result.output.count("FlakyTests > ${initializationErrorSyntheticTestMethodName(gradleVersion)} FAILED") == 1
result.output.count('FlakyTests > someTest PASSED') == 1
where:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class JUnit4ViaJUnitVintageFuncTest extends JUnit4FuncTest {
true
}

@Override
protected String initializationErrorSyntheticTestMethodName(String gradleVersion) {
gradleVersion == "5.0" ? "classMethod" : "initializationError"
}

protected String buildConfiguration() {
return '''
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class SpockFuncTest extends AbstractPluginFuncTest {
true
}

protected String initializationErrorSyntheticTestMethodName(String gradleVersion) {
"initializationError"
}

@Unroll
def "handles failure in #lifecycle (gradle version #gradleVersion)"() {
given:
Expand Down Expand Up @@ -87,14 +91,15 @@ class SpockFuncTest extends AbstractPluginFuncTest {
def result = gradleRunner(gradleVersion as String).build()
then:
result.output.count('SomeSpec > initializationError FAILED') == 1
result.output.count("SomeSpec > ${initializationErrorSyntheticTestMethodName(gradleVersion)} FAILED") == 1
result.output.count('SomeSpec > someTest PASSED') == 1
result.output.count('2 tests completed, 1 failed') == 1
where:
gradleVersion << GRADLE_VERSIONS_UNDER_TEST
}
@Unroll
def "handles @Stepwise tests (gradle version #gradleVersion)"() {
given:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class SpockViaJUnitVintageFuncTest extends SpockFuncTest {
false
}

@Override
protected String initializationErrorSyntheticTestMethodName(String gradleVersion) {
gradleVersion == "5.0" ? "classMethod" : "initializationError"
}

@Override
String testLanguage() {
'groovy'
Expand All @@ -30,7 +35,9 @@ class SpockViaJUnitVintageFuncTest extends SpockFuncTest {
protected String buildConfiguration() {
return """
dependencies {
testImplementation "org.codehaus.groovy:groovy-all:2.5.8"
testImplementation "org.codehaus.groovy:groovy-all:2.5.8", {
exclude group: "org.junit.jupiter"
}
testImplementation "org.spockframework:spock-core:1.3-groovy-2.5"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.6.2"
Expand Down

0 comments on commit d5ea91e

Please sign in to comment.