Gradle, testing test execution: support asserting reports from multiple tasks at once

This commit is contained in:
Sergey Rostov
2019-05-22 13:55:07 +03:00
parent a13f1a5e67
commit 709afdfa45
@@ -602,25 +602,30 @@ abstract class BaseGradleIT {
*/ */
fun CompiledProject.assertTestResults( fun CompiledProject.assertTestResults(
@TestDataFile assertionFileName: String, @TestDataFile assertionFileName: String,
testReportName: String vararg testReportNames: String
) { ) {
val projectDir = project.projectDir val projectDir = project.projectDir
val testReportDir = projectDir.resolve("build/test-results/$testReportName") val testReportDirs = testReportNames.map { projectDir.resolve("build/test-results/$it") }
if (!testReportDir.isDirectory) { testReportDirs.forEach {
error("Test report dir $testReportDir was not created") if (!it.isDirectory) {
error("Test report dir $it was not created")
}
} }
val actualTestResults = readAndCleanupTestResults(testReportDir, projectDir) val actualTestResults = readAndCleanupTestResults(testReportDirs, projectDir)
val expectedTestResults = prettyPrintXml(resourcesRootFile.resolve(assertionFileName).readText()) val expectedTestResults = prettyPrintXml(resourcesRootFile.resolve(assertionFileName).readText())
assertEquals(expectedTestResults, actualTestResults) assertEquals(expectedTestResults, actualTestResults)
} }
private fun readAndCleanupTestResults(testReportDir: File, projectDir: File): String { private fun readAndCleanupTestResults(testReportDirs: List<File>, projectDir: File): String {
val files = testReportDir val files = testReportDirs
.listFiles() .flatMap {
.filter { it.isFile && it.name.endsWith(".xml") } (it.listFiles() ?: arrayOf()).filter {
it.isFile && it.name.endsWith(".xml")
}
}
.sortedBy { .sortedBy {
// let containing test suite be first // let containing test suite be first
it.name.replace(".xml", ".A.xml") it.name.replace(".xml", ".A.xml")