diff --git a/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/json/JsonReporterTest.groovy b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/json/JsonReporterTest.groovy index 6f271d5..f55821e 100644 --- a/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/json/JsonReporterTest.groovy +++ b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/json/JsonReporterTest.groovy @@ -1,8 +1,6 @@ package io.github.platan.tests_execution_chart.reporters.json -import io.github.platan.tests_execution_chart.report.data.Mark -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.report.TestExecutionScheduleReportBuilder import spock.lang.Specification import spock.lang.TempDir @@ -18,9 +16,9 @@ class JsonReporterTest extends Specification { def "should generate report in json"() { given: def configOutputLocation = "my-output-location" - def report = new TestExecutionScheduleReport([ - new TimedTestResult('class', 'test', toEpochMilli('2023-03-10T19:00:02Z'), toEpochMilli('2023-03-10T19:00:05Z'), 'passed', TEST) - ], [new Mark('mark1', toEpochMilli('2023-03-10T19:00:05Z'))]) + def report = new TestExecutionScheduleReportBuilder() + .addResult('class', 'test', toEpochMilli('2023-03-10T19:00:02Z'), toEpochMilli('2023-03-10T19:00:05Z'), 'passed', TEST) + .addMark('mark1', toEpochMilli('2023-03-10T19:00:05Z')).build() def reporter = new JsonReporter().tap { it.setConfiguration(new JsonConfig(true, configOutputLocation)) } diff --git a/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/MermaidTestsReporterTest.groovy b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/MermaidTestsReporterTest.groovy new file mode 100644 index 0000000..9c152b2 --- /dev/null +++ b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/MermaidTestsReporterTest.groovy @@ -0,0 +1,48 @@ +package io.github.platan.tests_execution_chart.reporters.mermaid + +import io.github.platan.tests_execution_chart.report.TestExecutionScheduleReportBuilder +import spock.lang.Specification +import spock.lang.Subject +import spock.lang.TempDir + +import java.time.Instant + +import static io.github.platan.tests_execution_chart.report.data.TimedTestResult.Type.TEST + +class MermaidTestsReporterTest extends Specification { + + @TempDir + File baseDir + + def configOutputLocation = "my-output-location" + + @Subject + def reporter = new MermaidTestsReporter().tap { + it.setConfiguration(new MermaidConfig(true, configOutputLocation)) + } + + def "should generate report in mermaid format"() { + given: + def report = new TestExecutionScheduleReportBuilder() + .addResult('class', 'test', toEpochMilli('2023-03-10T19:00:02Z'), toEpochMilli('2023-03-10T19:00:05Z'), 'passed', TEST) + .addMark('mark1', toEpochMilli('2023-03-10T19:00:05Z')).build() + + when: + reporter.report(report, baseDir, "taskname") + + then: + def reportFile = new File(baseDir, "$configOutputLocation/taskname.txt") + reportFile.text == + """|gantt + |dateFormat YYYY-MM-DDTHH:mm:ss.SSSZZ + |axisFormat %H:%M:%S.%L + |section class + |test - 3000 ms :2023-03-10T20:00:02.000+0100, 2023-03-10T20:00:05.000+0100 + |mark1 : milestone, 2023-03-10T20:00:05.000+0100, 0 + |""".stripMargin() + } + + private static long toEpochMilli(String instant) { + Instant.parse(instant).toEpochMilli() + } +}