diff --git a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/TestExecutionReportFormatter.kt b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/TestExecutionReportFormatter.kt new file mode 100644 index 0000000..e9a87db --- /dev/null +++ b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/TestExecutionReportFormatter.kt @@ -0,0 +1,7 @@ +package io.github.platan.tests_execution_chart.reporters + +import io.github.platan.tests_execution_chart.report.data.TestExecutionScheduleReport + +interface TestExecutionReportFormatter { + fun format(report: TestExecutionScheduleReport): String +} diff --git a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/json/JsonReporter.kt b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/json/JsonReporter.kt index 5188b88..001641d 100644 --- a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/json/JsonReporter.kt +++ b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/json/JsonReporter.kt @@ -3,21 +3,16 @@ package io.github.platan.tests_execution_chart.reporters.json import io.github.platan.tests_execution_chart.report.ReportConfig import io.github.platan.tests_execution_chart.report.data.TestExecutionScheduleReport import io.github.platan.tests_execution_chart.reporters.GanttDiagramReporter -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json import java.io.File class JsonReporter : GanttDiagramReporter() { - private val json = Json { - prettyPrint = true - } override fun report( report: TestExecutionScheduleReport, baseDir: File, taskName: String ) { - val jsonReport = json.encodeToString(report) + val jsonReport = JsonTestExecutionReportFormatter().format(report) val reportFile = save(jsonReport, taskName, baseDir, config.outputLocation, "json") logger.lifecycle("Tests execution schedule report saved to ${reportFile.absolutePath} file.") } diff --git a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatter.kt b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatter.kt new file mode 100644 index 0000000..4fbbf12 --- /dev/null +++ b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatter.kt @@ -0,0 +1,16 @@ +package io.github.platan.tests_execution_chart.reporters.json + +import io.github.platan.tests_execution_chart.report.data.TestExecutionScheduleReport +import io.github.platan.tests_execution_chart.reporters.TestExecutionReportFormatter +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json + +class JsonTestExecutionReportFormatter : TestExecutionReportFormatter { + private val json = Json { + prettyPrint = true + } + + override fun format(report: TestExecutionScheduleReport): String { + return json.encodeToString(report) + } +} \ No newline at end of file diff --git a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatter.kt b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatter.kt index 4c92857..9c155e5 100644 --- a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatter.kt +++ b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatter.kt @@ -2,10 +2,11 @@ package io.github.platan.tests_execution_chart.reporters.mermaid import io.github.platan.tests_execution_chart.report.data.TestExecutionScheduleReport import io.github.platan.tests_execution_chart.report.data.TimedTestResult +import io.github.platan.tests_execution_chart.reporters.TestExecutionReportFormatter import io.github.platan.tests_execution_chart.reporters.mermaid.core.MermaidGanttDiagram import io.github.platan.tests_execution_chart.reporters.mermaid.core.MermaidGanttDiagramFormatter -class TestExecutionMermaidDiagramFormatter { +class TestExecutionMermaidDiagramFormatter : TestExecutionReportFormatter { companion object { val taskFormat: Map> = mapOf( @@ -14,7 +15,7 @@ class TestExecutionMermaidDiagramFormatter { ) } - fun format(report: TestExecutionScheduleReport): String { + override fun format(report: TestExecutionScheduleReport): String { val diagramBuilder = MermaidGanttDiagram.MermaidGanttDiagramBuilder() report.results.groupBy { result -> result.className }.forEach { (className, results) -> diagramBuilder.addSection(className.orEmpty()) diff --git a/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatterTest.groovy b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatterTest.groovy new file mode 100644 index 0000000..7616978 --- /dev/null +++ b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatterTest.groovy @@ -0,0 +1,29 @@ +package io.github.platan.tests_execution_chart.reporters.json + +import io.github.platan.tests_execution_chart.report.TestExecutionScheduleReportBuilder +import spock.lang.Specification +import spock.lang.Subject + +class JsonTestExecutionReportFormatterTest extends Specification { + + @Subject + def formatter = new JsonTestExecutionReportFormatter() + + def "should format empty report"() { + given: + def emptyReport = new TestExecutionScheduleReportBuilder().getResults() + + when: + def result = formatter.format(emptyReport) + + then: + result == + """{ + | "results": [ + | ], + | "marks": [ + | ] + |}""".stripMargin() + } + +}