ComposeTestRule

interface ComposeTestRule : TestRule
androidx.ui.test.ComposeTestRule

Enables to run tests of individual composables without having to do manual setup. For Android tests see AndroidComposeTestRule. 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 AndroidComposeTestRule directly and access its underlying ActivityTestRule

Summary

Public methods

abstract ComposeTestCaseSetup
forGivenContent(composable: () -> Unit)

Takes the given content and prepares it for execution-controlled test via ComposeTestCaseSetup.

abstract ComposeTestCaseSetup

Takes the given test case and prepares it for execution-controlled test via ComposeTestCaseSetup.

abstract Unit
runOnUiThread(action: () -> Unit)

Runs action on UI thread with a guarantee that any operations modifying Compose data model are safe to do in this block.

abstract Unit
setContent(composable: () -> Unit)

Sets the given composable as a content of the current screen.

Extension functions

From androidx.ui.test
CollectedSizes
ComposeTestRule.setContentAndCollectSizes(parentConstraints: DpConstraints = BigTestConstraints, children: () -> Unit)

Set content as with ComposeTestRule.setContent, but return CollectedSizes to assert width and height of this content

PxSize
ComposeTestRule.setContentAndGetPixelSize(parentConstraints: DpConstraints = BigTestConstraints, performSetContent: (() -> Unit) -> Unit = { setContent(it) }, children: () -> Unit)

Set content as with ComposeTestRule.setContent, but return sizes of this content

Properties

abstract Density

Current device screen's density.

abstract DisplayMetrics

Public methods

forGivenContent

abstract fun forGivenContent(composable: () -> Unit): ComposeTestCaseSetup

Takes the given content and prepares it for execution-controlled test via ComposeTestCaseSetup.

forGivenTestCase

abstract fun forGivenTestCase(testCase: ComposeTestCase): ComposeTestCaseSetup

Takes the given test case and prepares it for execution-controlled test via ComposeTestCaseSetup.

runOnUiThread

abstract fun runOnUiThread(action: () -> Unit): Unit

Runs action on UI thread with a guarantee that any operations modifying Compose data model are safe to do in this block.

setContent

abstract fun setContent(composable: () -> Unit): Unit

Sets the given composable as a content of the current screen.

Properties

density

abstract val density: Density

Current device screen's density.

displayMetrics

abstract val displayMetrics: DisplayMetrics