How to use HtmlReporter class of io.kotest.extensions.htmlreporter package

Best Kotest code snippet using io.kotest.extensions.htmlreporter.HtmlReporter

HtmlWriter.kt

Source:HtmlWriter.kt Github

copy

Full Screen

1package io.kotest.extensions.htmlreporter2import org.jdom2.DocType3import org.jdom2.Document4import org.jdom2.Element5import org.jdom2.Text6import java.nio.file.Path7class HtmlWriter(8 private val outputDir: Path9) {10 companion object {11 const val summaryTitle = "Test Summary"12 const val classTitle = "Class"13 const val homeAnchorHref = "Home"14 const val defaultStylesPath = "css/style.css"15 }16 fun buildSummaryDocument(summaryList: List<TestClassInfo>, stylesPath: String = defaultStylesPath): Document {17 return withDocument(stylesPath) { body ->18 body.addContent(Element("h1").setContent(Text(summaryTitle)))19 body.addContent(20 generateTestSummaryTable(21 listOf("Class", "Tests", "Errors", "Failures", "Skipped"),22 summaryList23 )24 )25 }26 }27 fun buildClassDocument(28 testClass: TestClassInfo,29 homepage: String,30 stylesPath: String = defaultStylesPath31 ): Document {32 return withDocument(stylesPath) { body ->33 body.addContent(Element("h1").setContent(Text("$classTitle ${testClass.name}")))34 body.addContent(Element("a").setText(homeAnchorHref).setAttribute("href", homepage))35 body.addContent(generateTestClassTable(testClass.testcases))36 }37 }38 private fun withDocument(stylesPath: String, block: (Element) -> Unit): Document {39 val document = Document()40 document.docType = DocType("html")41 val html = Element("html")42 val head = Element("head")43 val body = Element("body")44 head.addContent(45 Element("link")46 .setAttribute("rel", "stylesheet")47 .setAttribute("href", outputDir.resolve(stylesPath).toString())48 )49 block(body)50 html.addContent(head)51 html.addContent(body)52 document.addContent(html)53 return document54 }55 private fun addHeaderColumn(row: Element, value: String) = row.addContent(Element("th").setContent(Text(value)))56 private fun generateTestSummaryTable(headers: List<String>, testClasses: List<TestClassInfo>): Element {57 val table = Element("table")58 val headerRow = Element("tr")59 headers.forEach {60 addHeaderColumn(headerRow, it)61 }62 table.addContent(headerRow)63 testClasses.forEach { testClass ->64 val row = Element("tr")65 val anchor = Element("a")66 .setContent(Text(testClass.name))67 .setAttribute("href", "./classes/${testClass.name}.html")68 val tests = testClass.summary.tests.toIntOrNull() ?: 069 val errors = testClass.summary.errors.toIntOrNull() ?: 070 val failures = testClass.summary.failures.toIntOrNull() ?: 071 val skipped = testClass.summary.skipped.toIntOrNull() ?: 072 row.addContent(Element("td").setContent(anchor))73 row.addContent(Element("td").setContent(Text(tests.toString())))74 row.addContent(Element("td").setContent(Text(errors.toString())))75 row.addContent(Element("td").setContent(Text(failures.toString())))76 row.addContent(Element("td").setContent(Text(skipped.toString())))77 if((errors + failures + skipped) == 0) row.setAttribute("class", "success")78 if (failures > 0) row.setAttribute("class", "failure")79 table.addContent(row)80 }81 return table82 }83 private fun generateTestClassTable(testcases: List<TestCase>): Element {84 val table = Element("table")85 val headerRow = Element("tr")86 listOf("Test", "Duration", "Result").forEach { addHeaderColumn(headerRow, it) }87 table.addContent(headerRow)88 testcases.forEach { testCase ->89 val row = Element("tr")90 row.addContent(Element("td").setContent(Text(testCase.name)))91 row.addContent(Element("td").setContent(Text(testCase.duration)))92 row.addContent(Element("td").setContent(Text(testCase.result)))93 if (testCase.result == "Passed") {94 row.setAttribute("class", "success")95 } else {96 row.setAttribute("class", "failure")97 }98 table.addContent(row)99 }100 return table101 }102}...

Full Screen

Full Screen

HtmlReporter.kt

Source:HtmlReporter.kt Github

copy

Full Screen

...8import java.nio.file.Files9import java.nio.file.Path10import java.nio.file.Paths11import java.nio.file.StandardOpenOption12class HtmlReporter(13 private val outputDir: String = "reports/tests/test"14) : ProjectListener {15 companion object {16 const val DefaultLocation = "./reports/tests/test/"17 const val DefaultResultsLocation = "./build/test-results/test"18 const val BuildDirKey = "gradle.build.dir"19 }20 override suspend fun afterProject() {21 super.afterProject()22 val writer = HtmlWriter(outputDir())23 val testResults = getTestResults()24 val testClasses: MutableList<TestClassInfo> = mutableListOf()25 testResults.forEach {26 val builder = SAXBuilder()...

Full Screen

Full Screen

KotestConfig.kt

Source:KotestConfig.kt Github

copy

Full Screen

1package dev.adamko.config2import io.kotest.core.config.AbstractProjectConfig3import io.kotest.core.listeners.Listener4import io.kotest.extensions.htmlreporter.HtmlReporter5import io.kotest.extensions.junitxml.JunitXmlReporter6import io.kotest.property.Arb7import io.kotest.property.Exhaustive8import io.kotest.property.Gen9import io.kotest.property.arbitrary.IntShrinker10import io.kotest.property.arbitrary.arbitrary11import io.kotest.property.arbitrary.int12import io.kotest.property.arbitrary.merge13import kotlin.random.nextInt14class KotestConfig : AbstractProjectConfig() {15 override fun listeners(): List<Listener> = listOf(16 JunitXmlReporter(17 includeContainers = false,18 useTestPathAsName = true,19 ),20 HtmlReporter("reports/kotest")21 )22 companion object {23 inline fun <A, reified B : A> List<Gen<B>>.mergeAll(): Arb<A> =24 map { it.toArb() }25 .reduce { acc, gen -> acc.apply { merge(gen) } }26 inline fun <reified T> Gen<T>.toArb() = when (this) {27 is Arb<T> -> this28 is Exhaustive<T> -> toArb()29 }30 fun Arb.Companion.intEdgecases(31 min: Int = Int.MIN_VALUE,32 max: Int = Int.MAX_VALUE,33 additionalEdgecases: List<Int> = emptyList(),34 ) = Arb.intEdgecases(min..max, additionalEdgecases)...

Full Screen

Full Screen

CommonKotestProjectConfig.kt

Source:CommonKotestProjectConfig.kt Github

copy

Full Screen

1package xyz.gutgut.springbootkotlinexample.kotest2import io.kotest.core.config.AbstractProjectConfig3import io.kotest.core.extensions.Extension4import io.kotest.core.test.AssertionMode5import io.kotest.extensions.htmlreporter.HtmlReporter6import io.kotest.extensions.junitxml.JunitXmlReporter7abstract class CommonKotestProjectConfig : AbstractProjectConfig() {8 @Suppress("MagicNumber") override val parallelism = 39 override val assertionMode = AssertionMode.Warn10 override val globalAssertSoftly = true11 override fun extensions(): List<Extension> =12 listOf(JunitXmlReporter(includeContainers = false, useTestPathAsName = true), HtmlReporter())13}...

Full Screen

Full Screen

ProjectConfig.kt

Source:ProjectConfig.kt Github

copy

Full Screen

1package io.github.ricardorlg.devicefarm.tractor2import io.kotest.core.config.AbstractProjectConfig3import io.kotest.core.extensions.Extension4import io.kotest.extensions.htmlreporter.HtmlReporter5@Suppress("UNUSED")6object ProjectConfig : AbstractProjectConfig() {7 override val parallelism = 18 override fun extensions(): List<Extension> = listOf(HtmlReporter())9}...

Full Screen

Full Screen

HtmlReporter

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.extensions.SpecExtension2import io.kotest.core.spec.Spec3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.shouldBe5class HtmlReporterTest : StringSpec() {6 override fun extensions(): List<SpecExtension> = listOf(HtmlReporter())7 init {8 "this is a test" {9 }10 }11}12import io.kotest.core.extensions.SpecExtension13import io.kotest.core.spec.Spec14import io.kotest.core.spec.style.StringSpec15import io.kotest.matchers.shouldBe16class HtmlReporterTest : StringSpec() {17 override fun extensions(): List<SpecExtension> = listOf(HtmlReporter())18 init {19 "this is a test" {20 }21 }22}

Full Screen

Full Screen

HtmlReporter

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.FunSpec2import io.kotest.extensions.htmlreporter.HtmlReporter3class MyTest : FunSpec({4}) {5 override fun listeners() = listOf(HtmlReporter())6}7import io.kotest.core.spec.style.FunSpec8import io.kotest.extensions.junitxml.JunitXmlReporter9class MyTest : FunSpec({10}) {11 override fun listeners() = listOf(JunitXmlReporter())12}13import io.kotest.core.spec.style.FunSpec14import io.kotest.extensions.junitxml.JunitXmlReporter15class MyTest : FunSpec({16}) {17 override fun listeners() = listOf(JunitXmlReporter())18}19import io.kotest.core.spec.style.FunSpec20import io.kotest.extensions.junitxml.JunitXmlReporter21class MyTest : FunSpec({22}) {23 override fun listeners() = listOf(JunitXmlReporter())24}25import io.kotest.core.spec.style.FunSpec26import io.kotest.extensions.junitxml.JunitXmlReporter27class MyTest : FunSpec({28}) {29 override fun listeners() = listOf(JunitXmlReporter())30}31import io.kotest.core.spec.style.FunSpec32import io.kotest.extensions.junitxml.JunitXmlReporter33class MyTest : FunSpec({34}) {35 override fun listeners() = listOf(JunitXmlReporter())36}37import io.kotest.core.spec.style.FunSpec38import io.kotest.extensions.junitxml.JunitXmlReporter39class MyTest : FunSpec({40}) {41 override fun listeners() = listOf(JunitXmlReporter())42}43import io.kotest.core.spec.style.FunSpec44import io.kotest.extensions.junitxml.JunitXmlReporter45class MyTest : FunSpec({

Full Screen

Full Screen

HtmlReporter

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.DescribeSpec2import io.kotest.extensions.htmlreporter.HtmlReporter3import io.kotest.matchers.shouldBe4class HtmlReportTest : DescribeSpec({5 describe("A calculator") {6 HtmlReporter()7 context("addition") {8 it("should add two numbers") {9 (1 + 1) shouldBe 210 }11 }12 }13})14dependencies {15 testImplementation("io.kotest:kotest-runner-junit5:4.3.2")16 testImplementation("io.kotest:kotest-extensions-htmlreporter:4.3.2")17}

Full Screen

Full Screen

HtmlReporter

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2import io.kotest.extensions.htmlreporter.HtmlReporter3import io.kotest.matchers.shouldBe4class HtmlReporterDemo : StringSpec({5 extensions(HtmlReporter())6 "This test should pass" {7 }8})9Option Description Default htmlReporterOutputDir Directory in which HTML report will be generated. ${user.dir}/build/reports/kotest/html-reporter htmlReporterFilename Name of the HTML report file. report.html htmlReporterTemplateFile HTML template file. Default template is provided by kotest. null htmlReporterStylesheetFile CSS stylesheet file. Default stylesheet is provided by kotest. null htmlReporterIncludeSystemOut Include System.out in the report. true htmlReporterIncludeSystemErr Include System.err in the report. true htmlReporterIncludeCode Include test code in the report. true htmlReporterIncludeContainers Include containers in the report. true htmlReporterIncludeTags Include tags in the report. true htmlReporterIncludeDuration Include duration in the report. true htmlReporterIncludeLinks Include links in the report. true10import io.kotest.core.spec.style.StringSpec11import io.kotest.extensions.htmlreporter.HtmlReporter12import io.kotest.matchers.shouldBe13class HtmlReporterDemo : StringSpec({14 extensions(HtmlReporter(15 "This test should pass" {16 }17})

Full Screen

Full Screen

HtmlReporter

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.FunSpec2import io.kotest.extensions.htmlreporter.HtmlReporter3import io.kotest.matchers.shouldBe4class HtmlReporterTest : FunSpec({5config {6listeners(HtmlReporter())7}8test("HtmlReporterTest") {9}10})11HtmlReporter(outputDir = "build/reports/tests/")12dependencies {13testImplementation("io.kotest:kotest-runner-junit5-jvm:4.3.1")14testImplementation("io.kotest:kotest-extensions-htmlreporter-jvm:4.3.1")15}16import io.kotest.core.spec.style.FunSpec17import io.kotest.extensions.junit.JUnitHtmlReporter18import io.kotest.matchers.shouldBe19class JUnitHtmlReporterTest : FunSpec({20config {21listeners(JUnitHtmlReporter())22}23test("JUnitHtmlReporterTest") {24}25})26JUnitHtmlReporter(outputDir = "build/reports/tests/")

Full Screen

Full Screen

HtmlReporter

Using AI Code Generation

copy

Full Screen

1class HtmlReporterTest : FunSpec({2     val htmlReporter = HtmlReporter()3     registerListener(htmlReporter)4     test("test1") {5     }6     test("test2") {7     }8     test("test3") {9     }10})11class HtmlReporterTest : FunSpec({12     val htmlReporter = HtmlReporter(outputDir = "reports")13     registerListener(htmlReporter)14     test("test1") {15     }16     test("test2") {17     }18     test("test3") {19     }20})21class HtmlReporterTest : FunSpec({22     val htmlReporter = HtmlReporter(reportName = "myreport.html")23     registerListener(htmlReporter)24     test("test1") {25     }26     test("test2") {27     }28     test("test3") {29     }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in HtmlReporter

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful