Start native apps faster with the Composables CLI ->
Class

TestFailurePolicy

Configuration for the failure handling pipeline in Compose UI tests.

Source set: Android
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)
Source set: Common
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.

Properties

screenshotCaptureMode

Source set: Common
public val screenshotCaptureMode: CaptureMode

uiHierarchyCaptureMode

Source set: Common
public val uiHierarchyCaptureMode: CaptureMode

failureHandlers

Source set: Common
public val failureHandlers: List<TestFailureHandler>

Members

CaptureMode

Source set: Common
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

Source set: Common
public companion object

Properties

Unspecified

Source set: Common
public val Unspecified: CaptureMode

Fall back to the suite-level runner configuration.

Enabled

Source set: Common
public val Enabled: CaptureMode

Explicitly enable the capture for this test, overriding runner configuration.

Disabled

Source set: Common
public val Disabled: CaptureMode

Explicitly disable the capture for this test, overriding runner configuration.