Kotest JUnit XML Format Reporter
JUnit includes an XML report generator called the legacy XML report. Many tools integrate with this format, so it is very useful. However, this report has no concept of nested tests. Therefore, when used with nested testing styles in Kotest, parent tests are included as orphans.
To solve this problem, Kotest has its own implementation of the same format, and you can configure whether to include parent tests or collapse names.
To configure it in your project, add JunitXmlReporter using project configuration.
class MyConfig : AbstractProjectConfig() {
override fun extensions(): List<Extension> = listOf(
JunitXmlReporter(
includeContainers = false, // don't write out status for all tests
useTestPathAsName = true, // use the full test path (ie, includes parent test names)
outputDir = "../target/junit-xml" // include to set output dir for maven
)
)
}
The reporter also needs to know where the build output folder is by setting a system property. Gradle also needs to know that it should not generate its own JUnit XML report. Configure this in Gradle’s test block.
tasks.named<Test>("test") {
useJUnitPlatform()
reports {
junitXml.required.set(false)
}
systemProperty("gradle.build.dir", project.buildDir)
}
Parameters
The reporter has three parameters:
- If
includeContainersistrue, all intermediate tests are included in the report as their own tests. The default isfalse. - If
useTestPathAsNameistrue, the full test path is used as the name. In other words, the names of all parent tests are included in the name as a single string. - If
outputDiris set, reports are generated in that folder. The default istest-results/test.