Skip to content

Commit

Permalink
Rethrow exception to write report before finishing up the task
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensousa committed Sep 27, 2024
1 parent c3871cd commit eaa3bd0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ open class InstrumentedReportRule internal constructor(
action: InstrumentedBlockingTest.() -> Unit,
) {
val currentTest = getCurrentTest<InstrumentedBlockingTest>()
action(currentTest)
try {
action(currentTest)
} catch (error: Throwable) {
currentTest.onFailed(error)
throw error
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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
Expand Down Expand Up @@ -108,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")

Expand Down

0 comments on commit eaa3bd0

Please sign in to comment.