6월 3일의 ⁠#Android11: 베타 버전 출시 행사에 참여하세요.

AndroidComposeTestRule

class AndroidComposeTestRule<T : ComponentActivity> : ComposeTestRule
kotlin.Any
   ↳ androidx.ui.test.android.AndroidComposeTestRule

Android specific implementation of ComposeTestRule.

If recomposer is null the thread-specific Recomposer.current will be used when setContent is called.

Summary

Nested classes

inner

Public constructors

<init>(activityTestRule: ActivityTestRule<T>, recomposer: Recomposer? = null, disableTransitions: Boolean = false)

Android specific implementation of ComposeTestRule.

Public methods

Statement
apply(base: Statement, description: Description?)

Bitmap

Takes screenshot of the Activity's window after Compose UI gets idle.

ComposeTestCaseSetup
forGivenContent(composable: <ERROR CLASS>, Unit: <ERROR CLASS>)

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

ComposeTestCaseSetup

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

Unit
setContent(composable: <ERROR CLASS>, Unit: <ERROR CLASS>)

Inherited extension functions

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

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

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

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

Properties

ActivityTestRule<T>

AnimationClockTestRule

A test rule that allows you to control the animation clock

Density

Current device screen's density.

DisplayMetrics

Recomposer?

Public constructors

<init>

AndroidComposeTestRule(
    activityTestRule: ActivityTestRule<T>,
    recomposer: Recomposer? = null,
    disableTransitions: Boolean = false)

Android specific implementation of ComposeTestRule.

If recomposer is null the thread-specific Recomposer.current will be used when setContent is called.

Public methods

apply

fun apply(
    base: Statement,
    description: Description?
): Statement

captureScreenOnIdle

fun captureScreenOnIdle(): Bitmap

Takes screenshot of the Activity's window after Compose UI gets idle.

This function blocks until complete.

Note that this does not capture the full device screen as it has access only to the test Activity's window surface. The test Activity is the one that hosts the initial composition created via setContent. If there are windows on top of the Activity's window these won't be included. It will also not include any other Activities started afterwards.

You can also use SemanticsNodeInteraction.captureToBitmap to capture individual components. That one does not require any specific Activity.

forGivenContent

fun forGivenContent(
    composable: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): ComposeTestCaseSetup

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

forGivenTestCase

fun forGivenTestCase(testCase: ComposeTestCase): ComposeTestCaseSetup

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

setContent

fun setContent(
    composable: <ERROR CLASS>,
    Unit: <ERROR CLASS>
): Unit
Exceptions
IllegalStateException if called more than once per test.

Properties

activityTestRule

val activityTestRule: ActivityTestRule<T>

clockTestRule

val clockTestRule: AnimationClockTestRule

A test rule that allows you to control the animation clock

density

val density: Density

Current device screen's density.

displayMetrics

val displayMetrics: DisplayMetrics

recomposer

val recomposer: Recomposer?