-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JsonTestExecutionReportFormatter
- Loading branch information
Showing
5 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...n/kotlin/io/github/platan/tests_execution_chart/reporters/TestExecutionReportFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...io/github/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...b/platan/tests_execution_chart/reporters/json/JsonTestExecutionReportFormatterTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
|
||
} |