{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TestOwner

@InternalTestApi
public interface TestOwner


Provides necessary services to facilitate testing.

This is typically implemented by entities like test rule.

Summary

Public methods

abstract @NonNull MainTestClock

Clock that drives frames and recompositions in compose tests.

abstract @NonNull Set<@NonNull RootForTest>
getRoots(boolean atLeastOneRootExpected)

Collects all RootForTests from all compose hierarchies.

abstract @NonNull T
<T extends Object> runOnUiThread(@NonNull Function0<@NonNull T> action)

Runs the given action on the ui thread.

Public methods

getMainClock

abstract @NonNull MainTestClock getMainClock()

Clock that drives frames and recompositions in compose tests.

getRoots

abstract @NonNull Set<@NonNull RootForTestgetRoots(boolean atLeastOneRootExpected)

Collects all RootForTests from all compose hierarchies.

This is a blocking call. Returns only after compose is idle.

Can crash in case it hits time out. This is not supposed to be handled as it surfaces only in incorrect tests.

Parameters
boolean atLeastOneRootExpected

Whether the caller expects that at least one compose root is present in the tested app. This affects synchronization efforts / timeouts of this API.

runOnUiThread

abstract @NonNull T <T extends Object> runOnUiThread(@NonNull Function0<@NonNull T> action)

Runs the given action on the ui thread.

This is a blocking call.