Skip to main content
Version: 5.8

JUnit XML Format Reporter

Latest Release

JUnit includes an XML report generator that it calls the legacy xml report . Many tools integrate with this format so it is very useful. However, this report has no concept of nesting tests. Therefore when used with a nested test style in Kotest, it will include parent tests as orphans.

To solve this, Kotest has it's own implementation of the same format, that is configurable on whether to include parent tests and/or collapse the names.

note

The following module is needed: io.kotest:kotest-extensions-junitxml in your build. Search maven central for latest version here.

To configure in your project, you need to add the JunitXmlReporter using project config.

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
)
)
}

Additionally, the reporter needs to know where your build output folder is by setting a system property. Gradle also needs to know that it should not generate JUnit XML reports by itself. We configure that in the tests block in gradle.

tasks.named<Test>("test") {
useJUnitPlatform()
reports {
junitXml.required.set(false)
}
systemProperty("gradle.build.dir", project.buildDir)
}

Parameters​

The reporter has three parameters:

  • includeContainers when true, all intermediate tests are included in the report as tests in their own right. Defaults to false.
  • useTestPathAsName when true, the full test path will be used as the name. In other words the name will include the name of any parent tests as a single string.
  • outputDir when set, the reports are generated in that folder, default value is: test-results/test