# RootForTest

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/node/RootForTest.kt+class:androidx.compose.ui.node.RootForTest) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface RootForTest
  ```
Known direct subclasses [ViewRootForTest](https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewRootForTest)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ViewRootForTest` | The marker interface to be implemented by the `https://developer.android.com/reference/android/view/View.html` backing the composition. |

*** ** * ** ***

The marker interface to be implemented by the root backing the composition. To be used in tests.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest.UncaughtExceptionHandler` An optional error handler that can be set to catch exceptions thrown during the layout, draw, and teardown phases of the associated composition. |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#forceAccessibilityForTesting(kotlin.Boolean)(enable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Force accessibility to be enabled for testing. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#measureAndLayoutForTest()()` Requests another layout (measure + placement) pass be performed for any nodes that need it. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#runAndClearPendingCallbacks()()` Unregisters callbacks scheduled by delegating to the event queue (e.g. Handler on Android) and runs them immediately. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#sendIndirectPointerEvent(androidx.compose.ui.input.indirect.IndirectPointerEvent)(indirectPointerEvent: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/indirect/IndirectPointerEvent)` Sends `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/indirect/IndirectPointerEvent` to the focused component in this `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/Owner` for testing. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#sendKeyEvent(androidx.compose.ui.input.key.KeyEvent)(keyEvent: https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent)` Send this `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent` to the focused component in this `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/Owner`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#setAccessibilityEventBatchIntervalMillis(kotlin.Long)(intervalMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Set the time interval between sending accessibility events in milliseconds. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#setUncaughtExceptionHandler(androidx.compose.ui.node.RootForTest.UncaughtExceptionHandler)( handler: https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest.UncaughtExceptionHandler? )` Sets the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest.UncaughtExceptionHandler` callback to dispatch layout, measure, and draw exceptions from this Composition to. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#updateSemanticsForTest()()` Recalculates semantic node bounds for previously measured and laid out nodes. | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#density()` Current device density. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsOwner` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#semanticsOwner()` Semantics owner for this root. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/input/TextInputService` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#textInputService()` **This property is deprecated.** Use PlatformTextInputModifierNode instead. | Cmn |

## Public functions

### forceAccessibilityForTesting

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
open fun forceAccessibilityForTesting(enable: Boolean): Unit
```

Force accessibility to be enabled for testing.

| Parameters |
|---|---|
| `enable: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | force enable accessibility if true. |

### measureAndLayoutForTest

Cmn Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.4.0)

```
open fun measureAndLayoutForTest(): Unit
```

Requests another layout (measure + placement) pass be performed for any nodes that need it. This doesn't force anything to be remeasured that wouldn't be if `requestLayout` were called. However, unlike `requestLayout`, it doesn't merely *schedule* another layout pass to be performed, it actually performs it synchronously.

This method is used in UI tests to perform layout in between frames when pumping frames as fast as possible (i.e. without waiting for the choreographer to schedule them) in order to get to idle, e.g. during a `waitForIdle` call.

### runAndClearPendingCallbacks

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.13.0-rc01)

```
open fun runAndClearPendingCallbacks(): Unit
```

Unregisters callbacks scheduled by delegating to the event queue (e.g. Handler on Android) and runs them immediately.

This method is used to ensure that root instance does not leak when the event queue is not drained.

### sendIndirectPointerEvent

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
open fun sendIndirectPointerEvent(indirectPointerEvent: IndirectPointerEvent): Boolean
```

Sends `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/indirect/IndirectPointerEvent` to the focused component in this `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/Owner` for testing. In most cases, you should use the indirect testing APIs provided in ui-test. See `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IndirectPointerInjectionScope` for more information.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the event was consumed. False otherwise. |

### sendKeyEvent

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun sendKeyEvent(keyEvent: KeyEvent): Boolean
```

Send this `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/key/KeyEvent` to the focused component in this `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/Owner`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the event was consumed. False otherwise. |

### setAccessibilityEventBatchIntervalMillis

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.6.0)

```
open fun setAccessibilityEventBatchIntervalMillis(intervalMillis: Long): Unit
```

Set the time interval between sending accessibility events in milliseconds.

This is the delay before dispatching a recurring accessibility event in milliseconds. It delays the loop that sends events to the accessibility and content capture framework in batches. A recurring event will be sent at most once during the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest#setAccessibilityEventBatchIntervalMillis(kotlin.Long)` timeframe. The default time delay is 100 milliseconds.

### setUncaughtExceptionHandler

Cmn Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

```
open fun setUncaughtExceptionHandler(
    handler: RootForTest.UncaughtExceptionHandler?
): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/RootForTest.UncaughtExceptionHandler` callback to dispatch layout, measure, and draw exceptions from this Composition to. If this method is called multiple times, the previous callback is discarded.

The default test runners that ship with the Compose UI test and associated JUnit variation use this API to reroute exceptions back to the test under execution. Custom test runners may need to associate their own exception handler to do the same. If the Compose UI Test runner's exception handler is overwritten, it may lead to unhandled exceptions crashing the instrumented process and terminating the entire test suite early.

### updateSemanticsForTest

Cmn Added in [1.13.0-rc01](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.13.0-rc01)

```
open fun updateSemanticsForTest(): Unit
```

Recalculates semantic node bounds for previously measured and laid out nodes.

This method is used in benchmarks to isolate semantics update that is usually performed out of frame.

## Public properties

### density

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val density: Density
```

Current device density.

### semanticsOwner

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val semanticsOwner: SemanticsOwner
```

Semantics owner for this root. Manages all the semantics nodes.

### textInputService

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Deprecated in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val textInputService: TextInputService
```

> [!CAUTION]
> **This property is deprecated.**   
> Use PlatformTextInputModifierNode instead.

The service handling text input.