ComposeTestRule
interface ComposeTestRule : TestRule, SemanticsNodeInteractionsProvider
androidx.compose.ui.test.junit4.ComposeTestRule |
Enables to run tests of individual composables without having to do manual setup. For Android tests see createAndroidComposeRule. Normally this rule is obtained by using createComposeRule factory that provides proper implementation (depending if running host side or Android side).
However if you really need Android specific dependencies and don't want your test to be abstract you can still create createAndroidComposeRule directly and access its underlying Activity.
Summary
Public methods | |
---|---|
abstract suspend Unit |
Suspends until compose is idle. |
abstract Unit |
registerIdlingResource(idlingResource: IdlingResource) Registers an IdlingResource in this test. |
abstract T |
runOnIdle(action: () -> T) Executes the given action in the same way as runOnUiThread but also makes sure Compose is idle before executing it. |
abstract T |
runOnUiThread(action: () -> T) Runs the given action on the UI thread. |
abstract Unit |
setContent(composable: () -> Unit) Sets the given composable as a content of the current screen. |
abstract Unit |
unregisterIdlingResource(idlingResource: IdlingResource) Unregisters an IdlingResource from this test. |
abstract Unit |
Waits for compose to be idle. |
Inherited functions | |
---|---|
Inherited extension functions | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From androidx.compose.ui.test
|
Properties | |
---|---|
abstract AnimationClockTestRule |
A test rule that allows you to control the animation clock |
abstract Density |
Current device screen's density. |
abstract IntSize |
Current device display's size. |
Public methods
awaitIdle
abstract suspend fun awaitIdle(): Unit
Suspends until compose is idle. Compose is idle if there are no pending compositions, no pending changes that could lead to another composition, and no pending draw calls.
registerIdlingResource
abstract fun registerIdlingResource(idlingResource: IdlingResource): Unit
Registers an IdlingResource in this test.
runOnIdle
abstract fun <T> runOnIdle(action: () -> T): T
Executes the given action in the same way as runOnUiThread but also makes sure Compose is idle before executing it. This is great place for doing your assertions on shared variables.
This method is blocking until the action is complete.
runOnUiThread
abstract fun <T> runOnUiThread(action: () -> T): T
Runs the given action on the UI thread.
This method is blocking until the action is complete.
setContent
abstract fun setContent(composable: () -> Unit): Unit
Sets the given composable as a content of the current screen.
Use this in your tests to setup the UI content to be tested. This should be called exactly once per test.
Exceptions | |
---|---|
IllegalStateException |
if called more than once per test. |
unregisterIdlingResource
abstract fun unregisterIdlingResource(idlingResource: IdlingResource): Unit
Unregisters an IdlingResource from this test.
waitForIdle
abstract fun waitForIdle(): Unit
Waits for compose to be idle.
This is a blocking call. Returns only after compose is idle.
Can crash in case there is a time out. This is not supposed to be handled as it surfaces only in incorrect tests.
Properties
clockTestRule
abstract val clockTestRule: AnimationClockTestRule
A test rule that allows you to control the animation clock