diff --git a/src/main/kotlin/io/github/platan/tests_execution_chart/gradle/TestExecutionResultsRegisterService.kt b/src/main/kotlin/io/github/platan/tests_execution_chart/gradle/TestExecutionResultsRegisterService.kt index 3046b4a..6b629b7 100644 --- a/src/main/kotlin/io/github/platan/tests_execution_chart/gradle/TestExecutionResultsRegisterService.kt +++ b/src/main/kotlin/io/github/platan/tests_execution_chart/gradle/TestExecutionResultsRegisterService.kt @@ -23,8 +23,8 @@ abstract class TestExecutionResultsRegisterService : BuildService { val reportBuilders = if (module == null) register.results else register.results.filterKeys { it.identityPath.parent == module } - return reportBuilders.mapValues { it.value.getResults() } + return reportBuilders.mapValues { it.value.build() } } } diff --git a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/report/TestExecutionScheduleReportBuilder.kt b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/report/TestExecutionScheduleReportBuilder.kt index 69e351e..af6b89a 100644 --- a/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/report/TestExecutionScheduleReportBuilder.kt +++ b/tests-execution-chart-commons/src/main/kotlin/io/github/platan/tests_execution_chart/report/TestExecutionScheduleReportBuilder.kt @@ -1,22 +1,30 @@ package io.github.platan.tests_execution_chart.report +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 class TestExecutionScheduleReportBuilder { private var results = mutableListOf() - fun add( + private var marks = mutableListOf() + fun addResult( className: String?, testName: String, startTime: Long, endTime: Long, resultType: String, type: TimedTestResult.Type - ) { + ): TestExecutionScheduleReportBuilder { results.add(TimedTestResult(className, testName, startTime, endTime, resultType, type)) + return this } - fun getResults(): TestExecutionScheduleReport { - return TestExecutionScheduleReport(results) + fun addMark(name: String, timestamp: Long): TestExecutionScheduleReportBuilder { + marks.add(Mark(name, timestamp)) + return this + } + + fun build(): TestExecutionScheduleReport { + return TestExecutionScheduleReport(results, marks) } } 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 index 7616978..02ade62 100644 --- 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 @@ -4,6 +4,10 @@ import io.github.platan.tests_execution_chart.report.TestExecutionScheduleReport import spock.lang.Specification import spock.lang.Subject +import java.time.Instant + +import static io.github.platan.tests_execution_chart.report.data.TimedTestResult.Type.TEST + class JsonTestExecutionReportFormatterTest extends Specification { @Subject @@ -11,7 +15,7 @@ class JsonTestExecutionReportFormatterTest extends Specification { def "should format empty report"() { given: - def emptyReport = new TestExecutionScheduleReportBuilder().getResults() + def emptyReport = new TestExecutionScheduleReportBuilder().build() when: def result = formatter.format(emptyReport) @@ -26,4 +30,40 @@ class JsonTestExecutionReportFormatterTest extends Specification { |}""".stripMargin() } + def "should format report with one entry and one mark"() { + given: + def reportBuilder = 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')) + def report = reportBuilder.build() + + when: + def result = formatter.format(report) + + then: + result == + """{ + | "results": [ + | { + | "className": "class", + | "testName": "test", + | "startTime": 1678474802000, + | "endTime": 1678474805000, + | "resultType": "passed", + | "type": "TEST" + | } + | ], + | "marks": [ + | { + | "name": "mark1", + | "timestamp": 1678474805000 + | } + | ] + |}""".stripMargin() + } + + private static long toEpochMilli(String instant) { + Instant.parse(instant).toEpochMilli() + } + } diff --git a/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatterSpec.groovy b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatterSpec.groovy index fbe4ed4..5fa1df9 100644 --- a/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatterSpec.groovy +++ b/tests-execution-chart-commons/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/TestExecutionMermaidDiagramFormatterSpec.groovy @@ -16,14 +16,14 @@ class TestExecutionMermaidDiagramFormatterSpec extends Specification { def getDefault = TimeZone.getDefault() TimeZone.setDefault(SimpleTimeZone.getTimeZone(ZoneOffset.ofHours(2))) def reportBuilder = new TestExecutionScheduleReportBuilder() - reportBuilder.add('Test1', 'test1', 1681402397000, 1681402397100, 'SUCCESS', TEST) - reportBuilder.add('Test1', 'test2', 1681402397100, 1681402397300, 'SUCCESS', TEST) - reportBuilder.add('Test1', 'suite', 1681402397000, 1681402397300, 'SUCCESS', SUITE) - reportBuilder.add('Test2', 'test1', 1681402397000, 1681402397100, 'FAILURE', TEST) - reportBuilder.add('Test2', 'suite', 1681402397000, 1681402397300, 'FAILURE', SUITE) - reportBuilder.add('Test3', 'test1', 1681402397100, 1681402397300, 'SKIPPED', TEST) - reportBuilder.add('Test3', 'suite', 1681402397000, 1681402397300, 'SKIPPED', SUITE) - def report = reportBuilder.getResults() + .addResult('Test1', 'test1', 1681402397000, 1681402397100, 'SUCCESS', TEST) + .addResult('Test1', 'test2', 1681402397100, 1681402397300, 'SUCCESS', TEST) + .addResult('Test1', 'suite', 1681402397000, 1681402397300, 'SUCCESS', SUITE) + .addResult('Test2', 'test1', 1681402397000, 1681402397100, 'FAILURE', TEST) + .addResult('Test2', 'suite', 1681402397000, 1681402397300, 'FAILURE', SUITE) + .addResult('Test3', 'test1', 1681402397100, 1681402397300, 'SKIPPED', TEST) + .addResult('Test3', 'suite', 1681402397000, 1681402397300, 'SKIPPED', SUITE) + def report = reportBuilder.build() when: def mermaidReport = new TestExecutionMermaidDiagramFormatter().format(report) @@ -55,10 +55,10 @@ suite - 300 ms :2023-04-13T18:13:17.000+0200, 2023-04-13T18:13:17.300+0200 def getDefault = TimeZone.getDefault() TimeZone.setDefault(SimpleTimeZone.getTimeZone(ZoneOffset.ofHours(2))) def reportBuilder = new TestExecutionScheduleReportBuilder() - reportBuilder.add('Test1', 'test1', 1681402397000, 1681402397100, 'SUCCESS', TEST) - reportBuilder.add('Test1', 'test2', 1681402397100, 1681402397300, 'SUCCESS', TEST) - reportBuilder.add('Test2', 'test1', 1681402397000, 1681402397100, 'SUCCESS', TEST) - def results = reportBuilder.getResults() + .addResult('Test1', 'test1', 1681402397000, 1681402397100, 'SUCCESS', TEST) + .addResult('Test1', 'test2', 1681402397100, 1681402397300, 'SUCCESS', TEST) + .addResult('Test2', 'test1', 1681402397000, 1681402397100, 'SUCCESS', TEST) + def results = reportBuilder.build() def report = results.copy(results.results, [new Mark('mark1', 1681402397400)]) when: