-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Composite reporter that generates JUnit and HTML
- Loading branch information
Showing
11 changed files
with
144 additions
and
52 deletions.
There are no files selected for viewing
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
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
42 changes: 42 additions & 0 deletions
42
maestro-cli/src/main/java/maestro/cli/report/CompositeTestSuiteReporter.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,42 @@ | ||
package maestro.cli.report | ||
|
||
import maestro.cli.model.TestExecutionSummary | ||
import java.io.File | ||
|
||
class CompositeTestSuiteReporter(val reporters: Set<TestSuiteReporter>, override val fileExtension: String?) : TestSuiteReporter { | ||
override fun report( | ||
summary: TestExecutionSummary, | ||
out: File | ||
) { | ||
val baseReportDirectory = getBaseReportDirectory(out) | ||
|
||
reporters.forEach { reporter -> | ||
val reportFolder = File(baseReportDirectory, simpleReportFolderName(reporter)) | ||
reportFolder.mkdirs() | ||
|
||
val reportFile = File(reportFolder, "report${reporter.fileExtension}") | ||
|
||
if (reportFile.exists()) { | ||
reportFile.delete() | ||
} | ||
|
||
reporter.report(summary, reportFile) | ||
} | ||
} | ||
|
||
private fun getBaseReportDirectory(out: File): File { | ||
return if (out.absoluteFile.isDirectory) { | ||
out.absoluteFile | ||
} else { | ||
out.absoluteFile.parentFile | ||
} | ||
} | ||
|
||
private fun simpleReportFolderName(reporter: TestSuiteReporter): String { | ||
return reporter.javaClass.simpleName.replace(interfaceName, "") | ||
} | ||
|
||
companion object { | ||
private val interfaceName = TestSuiteReporter::class.simpleName!! | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
maestro-cli/src/main/java/maestro/cli/report/HtmlTestSuiteReporter.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
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
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
13 changes: 2 additions & 11 deletions
13
maestro-cli/src/main/java/maestro/cli/report/ReporterFactory.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 |
---|---|---|
@@ -1,16 +1,7 @@ | ||
package maestro.cli.report | ||
|
||
import maestro.cli.model.TestExecutionSummary | ||
import okio.BufferedSink | ||
|
||
object ReporterFactory { | ||
|
||
fun buildReporter(format: ReportFormat, testSuiteName: String?): TestSuiteReporter { | ||
return when (format) { | ||
ReportFormat.JUNIT -> JUnitTestSuiteReporter.xml(testSuiteName) | ||
ReportFormat.NOOP -> TestSuiteReporter.NOOP | ||
ReportFormat.HTML -> HtmlTestSuiteReporter() | ||
} | ||
return format.createReporter(testSuiteName) | ||
} | ||
|
||
} | ||
} |
12 changes: 7 additions & 5 deletions
12
maestro-cli/src/main/java/maestro/cli/report/TestSuiteReporter.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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
package maestro.cli.report | ||
|
||
import maestro.cli.model.TestExecutionSummary | ||
import okio.Sink | ||
import java.io.File | ||
|
||
interface TestSuiteReporter { | ||
val fileExtension: String? | ||
|
||
fun report( | ||
summary: TestExecutionSummary, | ||
out: Sink, | ||
out: File, | ||
) | ||
|
||
companion object { | ||
val NOOP: TestSuiteReporter = object : TestSuiteReporter { | ||
override fun report(summary: TestExecutionSummary, out: Sink) { | ||
override val fileExtension: String? = null | ||
|
||
override fun report(summary: TestExecutionSummary, out: File) { | ||
// no-op | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
maestro-cli/src/test/kotlin/maestro/cli/report/CompositeTestSuiteReporterTest.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,33 @@ | ||
package maestro.cli.report | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class CompositeTestSuiteReporterTest { | ||
|
||
@Test | ||
fun `Composite test report created`() { | ||
// Given | ||
val reportFormat = ReportFormat.COMPOSITE | ||
|
||
// When | ||
val reporter = reportFormat.createReporter("testSuiteName") | ||
|
||
// Then | ||
assertThat(reporter is CompositeTestSuiteReporter).isTrue() | ||
} | ||
|
||
@Test | ||
fun `Composite test report contains JUNIT and HTML reports`() { | ||
// Given | ||
val reportFormat = ReportFormat.COMPOSITE | ||
|
||
// When | ||
val reporter = reportFormat.createReporter("testSuiteName") | ||
val reporters = (reporter as CompositeTestSuiteReporter).reporters | ||
|
||
// Then | ||
assertThat(reporters.any { it is JUnitTestSuiteReporter }).isTrue() | ||
assertThat(reporters.any { it is HtmlTestSuiteReporter }).isTrue() | ||
} | ||
} |
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