public interface RootForTest
The marker interface to be implemented by the root backing the composition. To be used in tests.
Properties
density
public val density: Density
Current device density.
semanticsOwner
public val semanticsOwner: SemanticsOwner
Semantics owner for this root. Manages all the semantics nodes.
textInputService
@Deprecated("Use PlatformTextInputModifierNode instead.")
public val textInputService: TextInputService
The service handling text input.
Functions
sendKeyEvent
public fun sendKeyEvent(keyEvent: KeyEvent): Boolean
Send this KeyEvent to the focused component in this Owner.
Return
true if the event was consumed. False otherwise.
sendIndirectPointerEvent
public fun sendIndirectPointerEvent(indirectPointerEvent: IndirectPointerEvent): Boolean
Sends IndirectPointerEvent to the focused component in this Owner for testing. In most cases, you should use the indirect testing APIs provided in ui-test. See androidx.compose.ui.test.IndirectPointerInjectionScope for more information.
Return
true if the event was consumed. False otherwise.
forceAccessibilityForTesting
public fun forceAccessibilityForTesting(enable: Boolean)
Force accessibility to be enabled for testing.
Parameters
| enable | force enable accessibility if true. |
setAccessibilityEventBatchIntervalMillis
public fun setAccessibilityEventBatchIntervalMillis(intervalMillis: Long)
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 intervalMillis timeframe. The default time delay is 100 milliseconds.
measureAndLayoutForTest
public fun measureAndLayoutForTest()
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.
updateSemanticsForTest
public fun updateSemanticsForTest()
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.
runAndClearPendingCallbacks
public fun runAndClearPendingCallbacks()
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.
setUncaughtExceptionHandler
public fun setUncaughtExceptionHandler(handler: UncaughtExceptionHandler?)
Sets the 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.
Members
UncaughtExceptionHandler
public interface UncaughtExceptionHandler
An optional error handler that can be set to catch exceptions thrown during the layout, draw, and teardown phases of the associated composition. If an exception is thrown to this callback, the composition is already in an unrecoverable state and must be abandoned. Tests may choose to catch exceptions to forward or process them differently. By default, no exception handler is present and exceptions are thrown on the composer's thread, which may cause the process to crash.
This interface should generally not be used in production, and is intended for error routing or introspection rather than true error recovery.
Functions
onUncaughtException
public fun onUncaughtException(t: Throwable)
Invoked for testing infrastructure to be able to redirect an exception t that occurred during the layout, measure, or draw phase of the underlying view. When this function is invoked, the associated composition is in an unrecoverable state. The original exception may be re-thrown to propagate it.
If this callback swallows an exception to prevent a crash, you should expect other follow-up exceptions to be directed here as more operations are executed on the degenerate composition. The first exception passed to this callback is likely to be the only useful exception.
Parameters
| t | The exception thrown by the composition hierarchy during the layout, measure, or draw phase of the associated view. |