---
title: "TestFailurePolicy"
description: "Configuration for the failure handling pipeline in Compose UI tests."
type: "class"
---
## API Reference

> Source set: Android

```kotlin
public class TestFailurePolicy
```

Configuration for the failure handling pipeline in Compose UI tests.

A [TestFailurePolicy](/jetpack-compose/androidx.compose.ui/ui-test/classes/TestFailurePolicy/api) 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 [TestFailureHandler](/jetpack-compose/androidx.compose.ui/ui-test/interfaces/TestFailureHandler/api)s 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

```kotlin
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](/jetpack-compose/androidx.compose.ui/ui-test/classes/TestFailurePolicy/api) 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 [TestFailureHandler](/jetpack-compose/androidx.compose.ui/ui-test/interfaces/TestFailureHandler/api)s 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

```kotlin
public val screenshotCaptureMode: CaptureMode
```

### uiHierarchyCaptureMode

> Source set: Common

```kotlin
public val uiHierarchyCaptureMode: CaptureMode
```

### failureHandlers

> Source set: Common

```kotlin
public val failureHandlers: List<TestFailureHandler>
```

## Members

### CaptureMode

> Source set: Common

```kotlin
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](/jetpack-compose/androidx.compose.ui/ui-test/classes/TestFailurePolicy/api) 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

```kotlin
public companion object
```

## Properties

### Unspecified

> Source set: Common

```kotlin
public val Unspecified: CaptureMode
```

Fall back to the suite-level runner configuration.

### Enabled

> Source set: Common

```kotlin
public val Enabled: CaptureMode
```

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

### Disabled

> Source set: Common

```kotlin
public val Disabled: CaptureMode
```

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