Skip to content

Commit effd8f8

Browse files
Fix tests for new test report format (#471)
* Fix tests for new test report format --------- Signed-off-by: Jean Gauthier <jgauthier@gradle.com>
1 parent 790d225 commit effd8f8

3 files changed

Lines changed: 32 additions & 24 deletions

File tree

plugin/src/test/groovy/org/gradle/testretry/AbstractPluginFuncTest.groovy

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ abstract class AbstractPluginFuncTest extends Specification implements TestFrame
158158
toolchain {
159159
languageVersion = JavaLanguageVersion.of(${testJavaVersion})
160160
}
161-
}
161+
}
162162
"""
163163
} else {
164164
return ""
@@ -228,8 +228,8 @@ abstract class AbstractPluginFuncTest extends Specification implements TestFrame
228228
}
229229
}
230230

231-
def assertTestReportContains(String testClazz, String testName, int expectedSuccessCount, int expectedFailCount) {
232-
assertHtmlReportContains(testClazz, testName, expectedSuccessCount, expectedFailCount)
231+
def assertTestReportContains(String testClazz, String testName, int expectedSuccessCount, int expectedFailCount, String gradleVersion) {
232+
assertHtmlReportContains(testClazz, testName, expectedSuccessCount, expectedFailCount, GradleVersion.version(gradleVersion))
233233
assertXmlReportContains(testClazz, testName, expectedSuccessCount, expectedFailCount)
234234
true
235235
}
@@ -239,11 +239,19 @@ abstract class AbstractPluginFuncTest extends Specification implements TestFrame
239239
}
240240

241241
@SuppressWarnings("GroovyAssignabilityCheck")
242-
def assertHtmlReportContains(String testClazz, String testName, int expectedSuccessCount, int expectedFailCount) {
242+
def assertHtmlReportContains(String testClazz, String testName, int expectedSuccessCount, int expectedFailCount, GradleVersion gradleVersion) {
243243
def parser = new SAXParser()
244-
def page = new XmlSlurper(parser).parse(new File(testProjectDir.root, "build/reports/tests/test/classes/acme.${testClazz}.html"))
245-
assert page.'**'.findAll { it.name() == 'TR' && it.TD[0].text() == testName && it.TD[2].text() == 'passed' }.size() == expectedSuccessCount
246-
assert page.'**'.findAll { it.name() == 'TR' && it.TD[0].text() == testName && it.TD[2].text() == 'failed' }.size() == expectedFailCount
244+
def hasNewReportFormat = gradleVersion >= GradleVersion.version("9.3")
245+
def reportPath = "build/reports/tests/test/${hasNewReportFormat ? "acme.${testClazz}/index.html" : "classes/acme.${testClazz}.html"}"
246+
def page = new XmlSlurper(parser).parse(new File(testProjectDir.root, reportPath))
247+
if (hasNewReportFormat) {
248+
assert page.'**'.findAll { it.name() == 'TR' && it.TD[0].text() == testName }.sum { it -> it.TD[1].text() as int } == expectedSuccessCount + expectedFailCount // Tests
249+
assert page.'**'.findAll { it.name() == 'TR' && it.TD[0].text() == testName }.sum { it -> it.TD[2].text() as int } == expectedFailCount // Failures
250+
assert page.'**'.findAll { it.name() == 'TR' && it.TD[0].text() == testName }.sum { it -> it.TD[3].text() as int } == 0 // Skipped
251+
} else {
252+
assert page.'**'.findAll { it.name() == 'TR' && it.TD[0].text() == testName && it.TD[2].text() == 'passed' }.size() == expectedSuccessCount
253+
assert page.'**'.findAll { it.name() == 'TR' && it.TD[0].text() == testName && it.TD[2].text() == 'failed' }.size() == expectedFailCount
254+
}
247255
true
248256
}
249257

plugin/src/test/groovy/org/gradle/testretry/CorePluginFuncTest.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class CorePluginFuncTest extends AbstractGeneralPluginFuncTest {
4343
gradleRunner(gradleVersion).build()
4444
4545
then:
46-
assertTestReportContains("SuccessfulTests", reportedTestName("successTest"), 1, 0)
46+
assertTestReportContains("SuccessfulTests", reportedTestName("successTest"), 1, 0, gradleVersion)
4747
4848
where:
4949
gradleVersion << GRADLE_VERSIONS_UNDER_TEST
@@ -56,7 +56,7 @@ class CorePluginFuncTest extends AbstractGeneralPluginFuncTest {
5656
5757
then:
5858
result.output.contains("There were failing tests.")
59-
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 1)
59+
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 1, gradleVersion)
6060
6161
where:
6262
gradleVersion << GRADLE_VERSIONS_UNDER_TEST
@@ -80,8 +80,8 @@ class CorePluginFuncTest extends AbstractGeneralPluginFuncTest {
8080
// 2 individual tests FAILED + 1 overall task FAILED + 1 overall build FAILED
8181
result.output.count('FAILED') == 2 + 1 + 1
8282
83-
assertTestReportContains("SuccessfulTests", reportedTestName("successTest"), 1, 0)
84-
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 2)
83+
assertTestReportContains("SuccessfulTests", reportedTestName("successTest"), 1, 0, gradleVersion)
84+
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 2, gradleVersion)
8585
8686
where:
8787
gradleVersion << GRADLE_VERSIONS_UNDER_TEST
@@ -104,7 +104,7 @@ class CorePluginFuncTest extends AbstractGeneralPluginFuncTest {
104104
}
105105
106106
then:
107-
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 1)
107+
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 1, gradleVersion)
108108
109109
where:
110110
gradleVersion << GRADLE_VERSIONS_UNDER_TEST
@@ -127,7 +127,7 @@ class CorePluginFuncTest extends AbstractGeneralPluginFuncTest {
127127
it.count('FAILED') == 1
128128
}
129129
130-
assertTestReportContains("FlakyTests", reportedTestName("flaky"), 1, 1)
130+
assertTestReportContains("FlakyTests", reportedTestName("flaky"), 1, 1, gradleVersion)
131131
132132
where:
133133
gradleVersion << GRADLE_VERSIONS_UNDER_TEST

plugin/src/test/groovy/org/gradle/testretry/DevelocityPluginIntegrationFuncTest.groovy

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class DevelocityPluginIntegrationFuncTest extends AbstractGeneralPluginFuncTest
3636
def result = gradleRunner(gradleVersion, 'test', '--info').buildAndFail()
3737

3838
then:
39-
assertNotRetried(result)
39+
assertNotRetried(result, gradleVersion)
4040
result.output.contains("handled by the Develocity plugin")
4141

4242
where:
@@ -78,7 +78,7 @@ class DevelocityPluginIntegrationFuncTest extends AbstractGeneralPluginFuncTest
7878
def result = gradleRunner(gradleVersion).buildAndFail()
7979

8080
then:
81-
assertNotRetried(result)
81+
assertNotRetried(result, gradleVersion)
8282

8383
where:
8484
//noinspection GroovyAssignabilityCheck
@@ -94,7 +94,7 @@ class DevelocityPluginIntegrationFuncTest extends AbstractGeneralPluginFuncTest
9494
def result = gradleRunner(gradleVersion).buildAndFail()
9595

9696
then:
97-
assertRetried(result)
97+
assertRetried(result, gradleVersion)
9898

9999
where:
100100
//noinspection GroovyAssignabilityCheck
@@ -110,7 +110,7 @@ class DevelocityPluginIntegrationFuncTest extends AbstractGeneralPluginFuncTest
110110
def result = gradleRunner(gradleVersion).buildAndFail()
111111

112112
then:
113-
assertRetried(result)
113+
assertRetried(result, gradleVersion)
114114

115115
where:
116116
gradleVersion << GRADLE_VERSIONS_UNDER_TEST
@@ -127,26 +127,26 @@ class DevelocityPluginIntegrationFuncTest extends AbstractGeneralPluginFuncTest
127127
def result = gradleRunner(gradleVersion, 'test', '--info').buildAndFail()
128128

129129
then:
130-
assertNotRetried(result)
130+
assertNotRetried(result, gradleVersion)
131131
result.output.contains("handled by the Develocity plugin")
132132

133133
where:
134134
gradleVersion << GRADLE_VERSIONS_UNDER_TEST
135135
}
136136

137-
def assertRetried(BuildResult result) {
138-
assertRetries(result, 1)
137+
def assertRetried(BuildResult result, String gradleVersion) {
138+
assertRetries(result, 1, gradleVersion)
139139
}
140140

141-
def assertNotRetried(BuildResult result) {
142-
assertRetries(result, 0)
141+
def assertNotRetried(BuildResult result, String gradleVersion) {
142+
assertRetries(result, 0, gradleVersion)
143143
}
144144

145-
def assertRetries(BuildResult result, int retries) {
145+
def assertRetries(BuildResult result, int retries, String gradleVersion) {
146146
// 1 initial + retries + 1 overall task FAILED + 1 build FAILED
147147
with(result.output) {
148148
it.count('FAILED') == 1 + retries + 1 + 1
149149
}
150-
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 1 + retries)
150+
assertTestReportContains("FailedTests", reportedTestName("failedTest"), 0, 1 + retries, gradleVersion)
151151
}
152152
}

0 commit comments

Comments
 (0)