Google is committed to advancing racial equity for Black communities. See how.

ComposeTestRuleJUnit

interface ComposeTestRuleJUnit : ComposeTestRule, TestRule
androidx.ui.test.ComposeTestRuleJUnit

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 Unit
setContent(composable: () -> Unit)

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

Inherited functions
Inherited extension functions
From androidx.ui.test
SemanticsNodeInteractionCollection
ComposeTestRule.onAllNodesWithLabel(label: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds all semantics nodes with the given label as AccessibilityLabel.

SemanticsNodeInteractionCollection
ComposeTestRule.onAllNodesWithTag(testTag: String, useUnmergedTree: Boolean = false)

Finds all semantics nodes identified by the given tag.

SemanticsNodeInteractionCollection
ComposeTestRule.onAllNodesWithText(text: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds all semantics nodes with the given text.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithLabel(label: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds a semantics node with the given label as its accessibilityLabel.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithSubstring(text: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds a semantics node with text that contains the given substring.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithTag(testTag: String, useUnmergedTree: Boolean = false)

Finds a semantics node identified by the given tag.

SemanticsNodeInteraction
ComposeTestRule.onNodeWithText(text: String, ignoreCase: Boolean = false, useUnmergedTree: Boolean = false)

Finds a semantincs node with the given text.

SemanticsNodeInteraction
ComposeTestRule.onRoot(useUnmergedTree: Boolean = false)

Finds the root semantics node of the Compose tree.

Properties
abstract AnimationClockTestRule

A test rule that allows you to control the animation clock

Inherited properties

Public methods

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.

Properties

clockTestRule

abstract val clockTestRule: AnimationClockTestRule

A test rule that allows you to control the animation clock