mjstrasser / kotest-html-reporter

HTML test reporter for Kotest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kotest HTML Reporter

License Build Maven Central

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.

What is it?

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.

Feature: inline Markdown conversion

Kotest HTML Reporter converts inline Markdown in the names of specs and tests. It renders code, italic and bold test as expected.

Feature: description extension property for specs

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:

Rendered description

Quick start

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

Using snapshot builds

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

Configuration options

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.

Environment variables

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 Java ZoneId.of() method.

This project’s GitHub Actions build file shows an example of setting these variables.

Example report

Here is an example report showing table of contents and expansion of a stacktrace.

Example of rendered HTML Report

About

HTML test reporter for Kotest

License:Apache License 2.0


Languages

Language:Kotlin 96.0%Language:CSS 4.0%