diff --git a/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportGenerator.kt b/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportGenerator.kt index 432d74d1..ce93a1f4 100644 --- a/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportGenerator.kt +++ b/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportGenerator.kt @@ -43,7 +43,6 @@ class AllureReportGenerator( logcatOutputDir: File, outputDir: File, keepLogcatOnSuccess: Boolean, - deleteOriginalReports: Boolean ) { val reportDir = parser.findReportDir(testResultDir) ?: return val testReportFiles = parser.parseTestReports(reportDir) @@ -62,9 +61,6 @@ class AllureReportGenerator( outputDir = outputDir, logcatFile = logcatFile ) - if (deleteOriginalReports) { - testReportFile.file.delete() - } createContainerReport(testReportFile.report)?.let { moveContainerReport(it, testResultDir, outputDir) } diff --git a/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportPlugin.kt b/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportPlugin.kt index d2fb4ce0..7e3e7b16 100644 --- a/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportPlugin.kt +++ b/carioca-report/report-android-allure-gradle-plugin/src/main/kotlin/com/rubensousa/carioca/report/android/allure/gradle/AllureReportPlugin.kt @@ -58,7 +58,6 @@ class AllureReportPlugin : Plugin { val testOutputDir = project.layout.buildDirectory.file(testOutputDirPath).get().asFile val logcatOutputDir = project.layout.buildDirectory.file(logcatOutputDirPath).get().asFile val keepLogcatOnSuccess = extension?.keepLogcatOnSuccess ?: false - val deleteOriginalReports = extension?.deleteOriginalReports ?: true testOutputDir.mkdirs() project.tasks.register("cleanAllureReport") { it.group = "report" @@ -67,9 +66,7 @@ class AllureReportPlugin : Plugin { // Clean-up all the files from the output dirs // to avoid conflicts with the next report generation outputDir.deleteRecursively() - if (deleteOriginalReports) { - testOutputDir.deleteRecursively() - } + testOutputDir.deleteRecursively() } } @@ -83,7 +80,6 @@ class AllureReportPlugin : Plugin { logcatOutputDir = logcatOutputDir, outputDir = outputDir, keepLogcatOnSuccess = keepLogcatOnSuccess, - deleteOriginalReports = deleteOriginalReports ) println("Allure report generated in file:///$outputDirPath") } @@ -114,12 +110,6 @@ interface AllureReportExtension { */ var keepLogcatOnSuccess: Boolean? - /** - * True if the original reports should be removed after the allure reports are generated - * Default: true to save space - */ - var deleteOriginalReports: Boolean? - /** * The report output path. * Can be used to merge reports of multiple modules by using the same directory diff --git a/carioca-report/report-android/src/androidTest/java/com/rubensousa/carioca/report/android/InstrumentedReportRuleTest.kt b/carioca-report/report-android/src/androidTest/java/com/rubensousa/carioca/report/android/InstrumentedReportRuleTest.kt index 0b849ab5..40c480bd 100644 --- a/carioca-report/report-android/src/androidTest/java/com/rubensousa/carioca/report/android/InstrumentedReportRuleTest.kt +++ b/carioca-report/report-android/src/androidTest/java/com/rubensousa/carioca/report/android/InstrumentedReportRuleTest.kt @@ -87,4 +87,44 @@ class InstrumentedReportRuleTest { assertThat(execution.status).isEqualTo(ReportStatus.RUNNING) } + @Test + fun testBeforeStageIsPassedToReport() { + // given + val description = testDescriptionRule.getDescription() + reportRule.start(description) + val beforeTitle = "Something" + val beforeStep = "StepBefore" + + // when + reportRule.before(beforeTitle) { + step(beforeStep) + } + + // then + val report = reportRule.getCurrentReport() + val beforeStage = report.getStagesBefore().first() + assertThat(beforeStage.getTitle()).isEqualTo(beforeTitle) + assertThat(beforeStage.getTestStages().first().getTitle()).isEqualTo(beforeStep) + } + + @Test + fun testAfterStageIsPassedToReport() { + // given + val description = testDescriptionRule.getDescription() + reportRule.start(description) + val afterTitle = "Something" + val afterStep = "StepAfter" + + // when + reportRule.after(afterTitle) { + step(afterStep) + } + + // then + val report = reportRule.getCurrentReport() + val afterStage = report.getStagesAfter().first() + assertThat(afterStage.getTitle()).isEqualTo(afterTitle) + assertThat(afterStage.getTestStages().first().getTitle()).isEqualTo(afterStep) + } + } diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReportRule.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReportRule.kt index 6e8b04cd..01f44741 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReportRule.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReportRule.kt @@ -167,7 +167,12 @@ open class InstrumentedReportRule internal constructor( action: InstrumentedBlockingTest.() -> Unit, ) { val currentTest = getCurrentTest() - action(currentTest) + try { + action(currentTest) + } catch (error: Throwable) { + currentTest.onFailed(error) + throw error + } } } diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReporter.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReporter.kt index 85e29dcd..1ba66292 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReporter.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/InstrumentedReporter.kt @@ -16,6 +16,7 @@ package com.rubensousa.carioca.report.android +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import com.rubensousa.carioca.report.runtime.StageReport import com.rubensousa.carioca.report.runtime.TestMetadata import java.io.OutputStream @@ -42,7 +43,7 @@ interface InstrumentedReporter { fun writeTestReport( testMetadata: TestMetadata, report: StageReport, - storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + storageProvider: ReportStorageProvider, ): Result } diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/recording/ScreenRecorder.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/recording/ScreenRecorder.kt index fd24a5ef..b3fad620 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/recording/ScreenRecorder.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/recording/ScreenRecorder.kt @@ -17,12 +17,13 @@ package com.rubensousa.carioca.report.android.recording import android.util.Log +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import java.io.BufferedInputStream import java.io.File import java.io.FileInputStream internal class ScreenRecorder( - private val storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + private val storageProvider: ReportStorageProvider, private val taskFactory: RecordingTaskFactory, ) { diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/screenshot/ScreenshotDelegate.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/screenshot/ScreenshotDelegate.kt index 7fd70702..e1fba032 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/screenshot/ScreenshotDelegate.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/screenshot/ScreenshotDelegate.kt @@ -18,12 +18,13 @@ package com.rubensousa.carioca.report.android.screenshot import com.rubensousa.carioca.report.android.stage.InstrumentedStageReport import com.rubensousa.carioca.report.android.storage.FileIdGenerator +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import com.rubensousa.carioca.report.runtime.StageAttachment class ScreenshotDelegate( private val outputPath: String, private val defaultOptions: ScreenshotOptions, - private val storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + private val storageProvider: ReportStorageProvider, ) { fun takeScreenshot( @@ -32,7 +33,7 @@ class ScreenshotDelegate( optionsOverride: ScreenshotOptions? = null, ) { val options = optionsOverride ?: defaultOptions - val screenshotUri = com.rubensousa.carioca.report.android.screenshot.DeviceScreenshot.take( + val screenshotUri = DeviceScreenshot.take( storageDir = storageProvider.getOutputUri(outputPath), options = options, filename = FileIdGenerator.get() diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedStageReport.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedStageReport.kt index 9f45405f..fa92b6f8 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedStageReport.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedStageReport.kt @@ -16,6 +16,7 @@ package com.rubensousa.carioca.report.android.stage +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import com.rubensousa.carioca.report.runtime.StageAttachment import com.rubensousa.carioca.report.runtime.StageReport import java.io.OutputStream @@ -27,7 +28,7 @@ import java.io.OutputStream abstract class InstrumentedStageReport( private val type: InstrumentedStageType, protected val outputPath: String, - protected val storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + protected val storageProvider: ReportStorageProvider, ) : StageReport() { override fun getType(): String = type.id diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedTestReport.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedTestReport.kt index bcabcda7..059be9ac 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedTestReport.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/InstrumentedTestReport.kt @@ -26,7 +26,9 @@ import com.rubensousa.carioca.report.android.recording.ReportRecording import com.rubensousa.carioca.report.android.recording.ScreenRecorder import com.rubensousa.carioca.report.android.screenshot.ScreenshotDelegate import com.rubensousa.carioca.report.android.storage.FileIdGenerator +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import com.rubensousa.carioca.report.runtime.ReportProperty +import com.rubensousa.carioca.report.runtime.ReportStatus import com.rubensousa.carioca.report.runtime.StageAttachment import com.rubensousa.carioca.report.runtime.StageStack import com.rubensousa.carioca.report.runtime.TestMetadata @@ -40,7 +42,7 @@ import com.rubensousa.carioca.report.runtime.TestMetadata */ abstract class InstrumentedTestReport internal constructor( outputPath: String, - storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + storageProvider: ReportStorageProvider, val metadata: TestMetadata, protected val interceptors: List, private val recordingOptions: RecordingOptions, @@ -60,7 +62,7 @@ abstract class InstrumentedTestReport internal constructor( screenshotDelegate: ScreenshotDelegate, reporter: InstrumentedReporter, interceptors: List, - storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + storageProvider: ReportStorageProvider, ) : this( outputPath = outputPath, metadata = metadata, @@ -107,6 +109,15 @@ abstract class InstrumentedTestReport internal constructor( } fun onFailed(error: Throwable) { + /** + * We also call [onFailed] internally inside the test action reports, + * to ensure the report file is saved before the instrumentation marks the test as over. + * Since tests can just use the rule without using the stage reports, + * we can't distinguish the 2 use-cases without doing this + */ + if (getExecutionMetadata().status == ReportStatus.FAILED) { + return + } // Take a screenshot asap to record the state on failures screenshotDelegate.takeScreenshot(this, "Screenshot of failure") diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingDelegate.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingDelegate.kt index dc151044..3d1b0a06 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingDelegate.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingDelegate.kt @@ -25,6 +25,7 @@ import com.rubensousa.carioca.report.android.stage.InstrumentedScenario import com.rubensousa.carioca.report.android.stage.InstrumentedStageReport import com.rubensousa.carioca.report.android.stage.InstrumentedStageScope import com.rubensousa.carioca.report.android.stage.InstrumentedStageType +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import com.rubensousa.carioca.report.runtime.ExecutionIdGenerator import com.rubensousa.carioca.report.runtime.StageStack @@ -39,7 +40,7 @@ internal class InstrumentedBlockingDelegate( private val stack: StageStack, private val interceptors: List, private val outputPath: String, - private val storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + private val storageProvider: ReportStorageProvider, ) : InstrumentedStageScope { override fun screenshot(description: String, options: ScreenshotOptions?) { diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingStage.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingStage.kt index e125e089..c5df964c 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingStage.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingStage.kt @@ -22,12 +22,13 @@ import com.rubensousa.carioca.report.android.stage.InstrumentedScenario import com.rubensousa.carioca.report.android.stage.InstrumentedStageReport import com.rubensousa.carioca.report.android.stage.InstrumentedStageScope import com.rubensousa.carioca.report.android.stage.InstrumentedStageType +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider internal class InstrumentedBlockingStage( type: InstrumentedStageType, outputPath: String, delegateFactory: InstrumentedReportDelegateFactory, - storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + storageProvider: ReportStorageProvider, private val id: String, private val title: String, ) : InstrumentedStageReport( diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTest.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTest.kt index f4cb7f8b..c98085d5 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTest.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTest.kt @@ -29,6 +29,7 @@ import com.rubensousa.carioca.report.android.stage.InstrumentedStageScope import com.rubensousa.carioca.report.android.stage.InstrumentedStageType import com.rubensousa.carioca.report.android.stage.InstrumentedTestReport import com.rubensousa.carioca.report.android.stage.InstrumentedTestScope +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import com.rubensousa.carioca.report.runtime.ExecutionIdGenerator import com.rubensousa.carioca.report.runtime.TestMetadata @@ -39,7 +40,7 @@ internal class InstrumentedBlockingTest( screenshotDelegate: ScreenshotDelegate, reporter: InstrumentedReporter, interceptors: List, - storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + storageProvider: ReportStorageProvider, ) : InstrumentedTestReport( outputPath = outputPath, metadata = metadata, diff --git a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTestBuilder.kt b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTestBuilder.kt index 39751bbf..022d4c2b 100644 --- a/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTestBuilder.kt +++ b/carioca-report/report-android/src/main/kotlin/com/rubensousa/carioca/report/android/stage/internal/InstrumentedBlockingTestBuilder.kt @@ -21,11 +21,12 @@ import com.rubensousa.carioca.report.android.interceptor.CariocaInstrumentedInte import com.rubensousa.carioca.report.android.recording.RecordingOptions import com.rubensousa.carioca.report.android.screenshot.ScreenshotDelegate import com.rubensousa.carioca.report.android.screenshot.ScreenshotOptions +import com.rubensousa.carioca.report.android.storage.ReportStorageProvider import com.rubensousa.carioca.report.runtime.TestMetadata import com.rubensousa.carioca.report.runtime.TestReportConfig internal class InstrumentedBlockingTestBuilder( - private val storageProvider: com.rubensousa.carioca.report.android.storage.ReportStorageProvider, + private val storageProvider: ReportStorageProvider, ) { fun build( diff --git a/docs/allure_plugin.md b/docs/android-allure-plugin.md similarity index 100% rename from docs/allure_plugin.md rename to docs/android-allure-plugin.md diff --git a/docs/changelog_android_allure.md b/docs/changelog-android-allure.md similarity index 100% rename from docs/changelog_android_allure.md rename to docs/changelog-android-allure.md diff --git a/docs/changelog_junit4_rules.md b/docs/changelog-junit4-rules.md similarity index 100% rename from docs/changelog_junit4_rules.md rename to docs/changelog-junit4-rules.md diff --git a/docs/changelog_reports.md b/docs/changelog-reports.md similarity index 100% rename from docs/changelog_reports.md rename to docs/changelog-reports.md diff --git a/docs/changelog.md b/docs/changelog.md index 9f485489..5e649ed0 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,6 @@ Libraries: -- [Android Allure Gradle Plugin](changelog_android_allure.md) -- [Test reports](changelog_reports.md) -- [JUnit4 Rules](changelog_junit4_rules.md) +- [Android Allure Gradle Plugin](changelog-android-allure) +- [Test reports](changelog-reports) +- [JUnit4 Rules](changelog-junit4-rules) diff --git a/docs/index.md b/docs/index.md index ba0f15bb..86a67d42 100644 --- a/docs/index.md +++ b/docs/index.md @@ -20,7 +20,7 @@ implementation "com.rubensousa.carioca:report-json:{{ report.version }}" implementation "com.rubensousa.carioca:report-runtime:{{ report.version }}" ``` -Jump to [this guide](android_test_reports.md) for how to integrate this library. +Jump to [this guide](test-reports-android) for how to integrate this library. ## License diff --git a/docs/android_test_reports.md b/docs/test-reports-android.md similarity index 99% rename from docs/android_test_reports.md rename to docs/test-reports-android.md index c306843a..71120a92 100644 --- a/docs/android_test_reports.md +++ b/docs/test-reports-android.md @@ -250,6 +250,6 @@ and can be found in `build/outputs/connected_android_test_additional_output/**/c By default, those reports are in json format and are not really easily readable. To visualize them properly, this library ships with an [Allure](https://allurereport.org/) plugin that can be used to generate test reports based on -the metadata collected through each test execution. Check it out in [this page](allure_plugin.md). +the metadata collected through each test execution. Check it out in [this page](android-allure-plugin). diff --git a/mkdocs.yml b/mkdocs.yml index 32cf0db8..7cbef10a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -55,7 +55,7 @@ plugins: nav: - 'Overview': index.md - - 'Android Test Reports': android_test_reports.md - - 'Android Allure Plugin': allure_plugin.md + - 'Android Test Reports': test-reports-android.md + - 'Android Allure Plugin': android-allure-plugin.md - 'Changelog': changelog.md - 'API': api/ \ No newline at end of file