A Kotest framework extension for reporting test results in a single HTML file.
This example is the most recent report of the tests of Kotest HTML Reporter itself. It deliberately includes failing tests to demonstrate how those are rendered in a report.
Kotest HTML Reporter is intended to be used with meaningful test descriptions, in any Kotest style, to create useful specifications of the software under test.
Kotest HTML Reporter converts inline Markdown in the names of specs and tests. It renders code
,
italic and bold test as expected.
The description
extension property for specs enables you to describe the class or feature that is being tested by a
spec. For example:
internal class DispatcherTest : DescribeSpec({
description(
"""
| The `Dispatcher` object is responsible for dispatching `LogEvent`s to zero
| or more sinks.
""".trimMargin()
)
describe("sinksFor() function") {
describe("when no loggers are configured") {
it("returns no sinks") {
loggingConfiguration { }
Dispatcher.sinksFor(randomString(), randomLevel()) shouldHaveSize 0
}
}
// ...
}
})
is rendered as:
Add Kotest HTML Reporter to your Gradle project, for example:
dependencies {
// ...
testImplementation("io.kotest:kotest-runner-junit5:5.6.2")
testImplementation("com.michaelstrasser:kotest-html-reporter:0.7.0")
}
Configure Kotest to use HTML Reporter:
import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.extensions.Extension
import mjs.kotest.HtmlReporter
/** Create an HTML report for every test run. */
object KotestConfig : AbstractProjectConfig() {
override fun extensions(): List<Extension> = listOf(
HtmlReporter(),
)
}
If you want to use snapshot builds of Kotest HTML Reporter, specify these in your Gradle build:
repositories {
// ...
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
// ...
testImplementation("io.kotest:kotest-runner-junit5:5.6.2")
testImplementation("com.michaelstrasser:kotest-html-reporter:0.8.0-SNAPSHOT")
}
Kotest HTML Reporter accepts these configuration options, here showing default values:
HtmlReporter(
outputDir = "reports/kotest",
reportFilename = "kotest-report.html",
)
outputDir
: output directory, relative to Gradle build directory.reportFilename
: name of the HTML report file.
These environment variables affect the generated output.
GIT_COMMIT
: Display the commit identifier of the build that generated the report.GIT_MESSAGE
: Display the commit message of the build that generated the report.TIMEZONE
: Display the timestamp using this timezone. The specified value is passed to the JavaZoneId.of()
method.
This project’s GitHub Actions build file shows an example of setting these variables.
Here is an example report showing table of contents and expansion of a stacktrace.