public class TestFailurePolicy
Configuration for the failure handling pipeline in Compose UI tests.
A TestFailurePolicy dictates what diagnostic artifacts the testing framework should capture when a test fails (such as screenshots or UI tree dumps), and provides a mechanism to execute custom TestFailureHandlers to process those artifacts or report the failure.
By default, the capture modes are set to CaptureMode.Unspecified. This means the framework will fall back to the suite-level runner configuration to determine if artifacts should be generated. Setting a mode explicitly to CaptureMode.Enabled or CaptureMode.Disabled will override the suite-level configuration for the specific test using this policy.
On Android, when a mode is CaptureMode.Unspecified, the framework falls back to reading suite-level arguments from the InstrumentationRegistry. You can configure these globally in your build.gradle via testInstrumentationRunnerArguments:
androidx.compose.ui.test.failure.isScreenshotCaptureEnabled(true/false)androidx.compose.ui.test.failure.isUiHierarchyCaptureEnabled(true/false)
public class TestFailurePolicy(
screenshotCaptureMode: CaptureMode = CaptureMode.Unspecified,
uiHierarchyCaptureMode: CaptureMode = CaptureMode.Unspecified,
failureHandlers: List<TestFailureHandler> = emptyList(),
)
Configuration for the failure handling pipeline in Compose UI tests.
A TestFailurePolicy dictates what diagnostic artifacts the testing framework should capture when a test fails (such as screenshots or UI tree dumps), and provides a mechanism to execute custom TestFailureHandlers to process those artifacts or report the failure.
By default, the capture modes are set to CaptureMode.Unspecified. This means the framework will fall back to the suite-level runner configuration (e.g., Instrumentation arguments on Android) to determine if artifacts should be generated. Setting a mode explicitly to CaptureMode.Enabled or CaptureMode.Disabled will override the suite-level configuration for the specific test using this policy.
Parameters
| screenshotCaptureMode | Determines whether a visual screenshot of the screen/UI should be captured upon failure. |
| uiHierarchyCaptureMode | Determines whether a text-based dump of the UI and semantics trees should be captured upon failure. |
| failureHandlers | A list of custom TestFailureHandlers that will be invoked in sequence after the framework completes its artifact generation. |
Properties
screenshotCaptureMode
public val screenshotCaptureMode: CaptureMode
Determines whether a visual screenshot of the screen/UI should be captured upon failure.
uiHierarchyCaptureMode
public val uiHierarchyCaptureMode: CaptureMode
Determines whether a text-based dump of the UI and semantics trees should be captured upon failure.
failureHandlers
public val failureHandlers: List<TestFailureHandler>
A list of custom TestFailureHandlers that will be invoked in sequence after the framework completes its artifact generation.
Members
CaptureMode
public class CaptureMode private constructor(private val value: Int)
Represents a tri-state flag for failure artifact captures, allowing individual test configurations to explicitly override or fall back to suite-level runner arguments.
This is used within TestFailurePolicy to dictate whether the test framework should capture diagnostic artifacts (like screenshots or UI hierarchy dumps) when a test fails.
Members
Companion
public companion object
Properties
Unspecified
public val Unspecified: CaptureMode
Fall back to the suite-level runner configuration.
Enabled
public val Enabled: CaptureMode
Explicitly enable the capture for this test, overriding runner configuration.
Disabled
public val Disabled: CaptureMode
Explicitly disable the capture for this test, overriding runner configuration.