Gradle, testing test execution: support asserting reports from multiple tasks at once
This commit is contained in:
+18
-13
@@ -601,30 +601,35 @@ abstract class BaseGradleIT {
|
|||||||
* @param assertionFileName path to xml with expected test results, relative to test resources root
|
* @param assertionFileName path to xml with expected test results, relative to test resources root
|
||||||
*/
|
*/
|
||||||
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 {
|
||||||
.sortedBy {
|
it.isFile && it.name.endsWith(".xml")
|
||||||
// let containing test suite be first
|
|
||||||
it.name.replace(".xml", ".A.xml")
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
.sortedBy {
|
||||||
|
// let containing test suite be first
|
||||||
|
it.name.replace(".xml", ".A.xml")
|
||||||
|
}
|
||||||
|
|
||||||
val xmlString = buildString {
|
val xmlString = buildString {
|
||||||
appendln("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
appendln("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
|
||||||
|
|||||||
Reference in New Issue
Block a user