asserting-node-state-and-text
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAsserting Node State and Text — Verify Through the Framework, Not Through fetchSemanticsNode
fetchSemanticsNode断言节点状态和文本——通过框架验证,而不是通过 fetchSemanticsNode
fetchSemanticsNodeOnce a finder resolves to a , the next step is asserting it. Compose ships a typed assertion for almost every semantic property; the generic covers the rest. This skill picks the right assertion, distinguishes "exists" from "displayed", and shows when boolean predicates belong inside .
SemanticsNodeInteractionassert(matcher)waitUntilfinder 解析为 后,下一步就是断言。Compose 为几乎所有 semantics 属性都提供了类型化断言;通用的 可覆盖其余情况。本 skill 会选择合适的断言,区分“存在于 semantics 树”与“已显示”,并说明何时应在 中使用布尔谓词。
SemanticsNodeInteractionassert(matcher)waitUntilWhen to use this skill
何时使用此 skill
- The developer wants to verify a Switch is on, a Checkbox is unchecked, a Button is enabled, a Text equals an expected string.
- The developer asks about vs
assertIsDisplayed(one verifies on-screen, the other verifies presence in the tree).assertExists - The developer needs a custom assertion via for a property without a typed extension.
assert(matcher) - The developer wants to verify a collection: "exactly 3 items", "at least one is selected", "all are enabled".
- A test compares directly instead of using a typed assertion.
node.config[...]
- 开发者希望验证 Switch 已开启、Checkbox 未选中、Button 已启用,或 Text 等于预期字符串。
- 开发者询问 与
assertIsDisplayed的区别:前者验证节点是否在屏幕上,后者验证节点是否存在于树中。assertExists - 开发者需要通过 为没有类型化扩展的属性编写自定义断言。
assert(matcher) - 开发者需要验证集合,例如“恰好有 3 个项目”“至少有一个被选中”或“全部已启用”。
- 测试直接比较 ,而没有使用类型化断言。
node.config[...]
When NOT to use this skill
何时不应使用此 skill
- The right node cannot be located — see .
../../finders/finding-nodes-by-tag-text-content/SKILL.md - The assertion is geometric (width, height, position) — see .
./asserting-bounds-and-dimensions/SKILL.md - The check needs a custom — see
SemanticsMatcher.../../finders/composing-semantics-matchers/SKILL.md - The state changes asynchronously and the assertion is timing-sensitive — see .
../../synchronization/synchronizing-with-idle/SKILL.md
- 无法定位目标节点——参见 。
../../finders/finding-nodes-by-tag-text-content/SKILL.md - 断言涉及几何属性(宽度、高度、位置)——参见 。
./asserting-bounds-and-dimensions/SKILL.md - 检查需要自定义 ——参见
SemanticsMatcher。../../finders/composing-semantics-matchers/SKILL.md - 状态异步变化且断言对时序敏感——参见 。
../../synchronization/synchronizing-with-idle/SKILL.md
Prerequisites
前置条件
- A working /
ComposeTestRule. SeeComposeUiTest.../../setup/configuring-test-dependencies/SKILL.md - The node has been located through /
onNode*/ a navigator.onAllNodes* - For semantics, the node must be composed AND placed AND at least partially on-screen post-clip (
assertIsDisplayed).Assertions.kt:30-39
- 可正常工作的 /
ComposeTestRule。参见ComposeUiTest。../../setup/configuring-test-dependencies/SKILL.md - 已通过 /
onNode*/ navigator 定位到目标节点。onAllNodes* - 对于 的语义,节点必须已组合、已放置,并且在 post-clip 后至少部分位于屏幕内(
assertIsDisplayed)。Assertions.kt:30-39
Workflow
工作流
-
1. Pick by question type. Map the developer's question to one assertion call. Every API listed is inunless noted.
commonMain/.../Assertions.ktQuestion API File:line Is it in the tree? assertExists(errorMessageOnFail)SemanticsNodeInteraction.kt:124-127Is it gone? assertDoesNotExist()SemanticsNodeInteraction.kt:94-110Is it a SubcomposeLayout retained child? assertIsDeactivated()SemanticsNodeInteraction.kt:137-148Is it visible to the user? /assertIsDisplayed()assertIsNotDisplayed()Assertions.kt:32-53Is it interactive? /assertIsEnabled()assertIsNotEnabled()Assertions.kt:60-67Is the toggle on? /assertIsOn()/assertIsOff()assertIsToggleable()Assertions.kt:74-81, 103Is the radio/tab selected? /assertIsSelected()/assertIsNotSelected()assertIsSelectable()Assertions.kt:88-110Does it have focus? /assertIsFocused()assertIsNotFocused()Assertions.kt:117-124Does it equal these strings? assertTextEquals(vararg, includeEditableText=true)Assertions.kt:181-185Does it contain this string? assertTextContains(value, substring=false, ignoreCase=false)Assertions.kt:204-208Content description equals these? assertContentDescriptionEquals(vararg)Assertions.kt:139-141Content description contains this? assertContentDescriptionContains(value, substring, ignoreCase)Assertions.kt:158-163StateDescription equals X? assertValueEquals(value)Assertions.kt:216-217ProgressBar at this position? assertRangeInfoEquals(rangeInfo)Assertions.kt:225-227Has a click action? /assertHasClickAction()assertHasNoClickAction()Assertions.kt:234-243Anything else assert(matcher, messagePrefixOnError = null)Assertions.kt:254-267 -
2.vs
assertIsDisplayed— pick deliberately. A nodeassertExistsif it is in the semantics tree (composed). A nodeassertExists()if it is composed AND placed AND at least partially visible after clipping (assertIsDisplayed()). For LazyColumn items not yet scrolled into view,Assertions.kt:30-39may fail (item not composed) or succeed (item composed but off-screen — depends on prefetch);assertExists()is the right gate for "the user sees this".assertIsDisplayed() -
3. Use the typed assertion, not. Typed assertions delegate to the matcher library and produce framework-formatted errors that name the failed property and dump the node (
fetchSemanticsNode().config[...]— the genericAssertions.kt:254-267buildsassert). Direct config reads bypass that error reporting and miss the auto-attached node dump.buildGeneralErrorMessage(errorMessageOnFail, selector, node) -
4. For collections, use the collection-typed assertions.for cardinality (
assertCountEquals(expectedSize)),Assertions.kt:276-292for "at least one matches" (fails on empty —assertAny(matcher)),Assertions.kt:300-312for "every node matches" (passes on empty —assertAll(matcher)).Assertions.kt:323-339 -
5. Forpredicates, use boolean APIs, not throwing assertions.
waitUntilreturnsisDisplayed()(Boolean) — perfect forAssertions.kt:351.rule.waitUntil { node.isDisplayed() }is its inverse (isNotDisplayed()). Both throw if multiple nodes match the finder, but never on zero. Cross-reference:Assertions.kt:361.../../synchronization/synchronizing-with-idle/SKILL.md -
6. For one-off properties without a typed assertion, use. Combine with prebuilt or composed matchers from
assert(matcher). The../../finders/composing-semantics-matchers/SKILL.mdlambda is for adding context when this assert is a precondition for a larger operation.messagePrefixOnError
-
1. 按问题类型选择。 将开发者的问题映射到一次断言调用。除非另有说明,下列 API 均位于。
commonMain/.../Assertions.kt问题 API 文件:行 它是否在树中? assertExists(errorMessageOnFail)SemanticsNodeInteraction.kt:124-127它是否已消失? assertDoesNotExist()SemanticsNodeInteraction.kt:94-110它是否为 SubcomposeLayout 保留的子项? assertIsDeactivated()SemanticsNodeInteraction.kt:137-148用户是否可以看到它? /assertIsDisplayed()assertIsNotDisplayed()Assertions.kt:32-53它是否可以交互? /assertIsEnabled()assertIsNotEnabled()Assertions.kt:60-67开关是否已开启? /assertIsOn()/assertIsOff()assertIsToggleable()Assertions.kt:74-81, 103单选按钮或标签页是否已选中? /assertIsSelected()/assertIsNotSelected()assertIsSelectable()Assertions.kt:88-110它是否拥有焦点? /assertIsFocused()assertIsNotFocused()Assertions.kt:117-124它是否等于这些字符串? assertTextEquals(vararg, includeEditableText=true)Assertions.kt:181-185它是否包含这个字符串? assertTextContains(value, substring=false, ignoreCase=false)Assertions.kt:204-208内容描述是否等于这些值? assertContentDescriptionEquals(vararg)Assertions.kt:139-141内容描述是否包含这个值? assertContentDescriptionContains(value, substring, ignoreCase)Assertions.kt:158-163StateDescription 是否等于 X? assertValueEquals(value)Assertions.kt:216-217ProgressBar 是否处于这个位置? assertRangeInfoEquals(rangeInfo)Assertions.kt:225-227它是否具有点击操作? /assertHasClickAction()assertHasNoClickAction()Assertions.kt:234-243其他情况 assert(matcher, messagePrefixOnError = null)Assertions.kt:254-267 -
2.与
assertIsDisplayed——有意识地选择。 如果契约只是要求节点存在于 semantics 树中(已组合),使用assertExists。如果要求节点已组合、已放置,并且裁剪后至少部分可见,使用assertExists()。对于尚未滚动到视野中的 LazyColumn 项目,assertIsDisplayed()可能失败(项目尚未组合),也可能成功(项目已组合但位于屏幕外——取决于预取行为);如果要验证“用户可以看到它”,assertExists()才是正确的判断方式。assertIsDisplayed() -
3. 使用类型化断言,不要使用。 类型化断言会委托给 matcher 库,并生成由框架格式化的错误信息,指出失败的属性并转储节点(
fetchSemanticsNode().config[...]——通用Assertions.kt:254-267会构建assert)。直接读取 config 会绕过错误报告,并遗漏自动附加的节点转储。buildGeneralErrorMessage(errorMessageOnFail, selector, node) -
4. 对于集合,使用面向集合的类型化断言。 使用检查基数(
assertCountEquals(expectedSize));使用Assertions.kt:276-292表达“至少有一个匹配”(空集合时失败——assertAny(matcher));使用Assertions.kt:300-312表达“每个节点都匹配”(空集合时通过——assertAll(matcher))。Assertions.kt:323-339 -
5. 对于谓词,使用返回 Boolean 的 API,而不是会抛出异常的断言。
waitUntil返回isDisplayed()(Boolean),非常适合Assertions.kt:351。rule.waitUntil { node.isDisplayed() }与其相反(isNotDisplayed())。当 finder 匹配到多个节点时,两者都会抛出异常,但节点数为零时不会抛出。交叉参考:Assertions.kt:361。../../synchronization/synchronizing-with-idle/SKILL.md -
6. 对于没有类型化断言的一次性属性,使用。 可以将其与
assert(matcher)中的预构建或组合 matcher 配合使用。当该断言是较大操作的前置条件时,可以使用../../finders/composing-semantics-matchers/SKILL.mdlambda 补充上下文。messagePrefixOnError
Patterns
模式
Pattern: assertIsDisplayed
over assertExists
for user-facing checks
assertIsDisplayedassertExists模式:面向用户的检查使用 assertIsDisplayed
,而不是 assertExists
assertIsDisplayedassertExistskotlin
// WRONG
@Test
fun submit_isVisibleAfterError() {
rule.setContent { CheckoutScreen(state = state) }
rule.onNodeWithTag(SubmitTag).assertExists()
}
// WRONG because: assertExists passes for nodes that are composed but off-screen, behind a
// dialog, or measured to zero size. The test does not prove the user actually sees the button.kotlin
// RIGHT
@Test
fun submit_isVisibleAfterError() {
rule.setContent { CheckoutScreen(state = state) }
rule.onNodeWithTag(SubmitTag).assertIsDisplayed()
}kotlin
// WRONG
@Test
fun submit_isVisibleAfterError() {
rule.setContent { CheckoutScreen(state = state) }
rule.onNodeWithTag(SubmitTag).assertExists()
}
// WRONG because: assertExists passes for nodes that are composed but off-screen, behind a
// dialog, or measured to zero size. The test does not prove the user actually sees the button.kotlin
// RIGHT
@Test
fun submit_isVisibleAfterError() {
rule.setContent { CheckoutScreen(state = state) }
rule.onNodeWithTag(SubmitTag).assertIsDisplayed()
}Pattern: typed assertIsOn
over manual config reads
assertIsOn模式:使用类型化 assertIsOn
,而不是手动读取 config
assertIsOnkotlin
// WRONG
@Test
fun darkMode_switch_isOn() {
rule.setContent { SettingsScreen() }
val node = rule.onNodeWithTag(DarkModeSwitchTag).fetchSemanticsNode()
assertEquals(ToggleableState.On, node.config[SemanticsProperties.ToggleableState])
}
// WRONG because: bypasses the framework's error reporting. Failure prints a JUnit assertEquals
// diff with no node dump, no selector description, no hint about which screen the failure
// happened on.kotlin
// RIGHT
@Test
fun darkMode_switch_isOn() {
rule.setContent { SettingsScreen() }
rule.onNodeWithTag(DarkModeSwitchTag).assertIsOn()
}assertIsOnassert(isOn())Assertions.kt:74isOn()expectValue(SemanticsProperties.ToggleableState, ToggleableState.On)Filters.kt:61-62kotlin
// WRONG
@Test
fun darkMode_switch_isOn() {
rule.setContent { SettingsScreen() }
val node = rule.onNodeWithTag(DarkModeSwitchTag).fetchSemanticsNode()
assertEquals(ToggleableState.On, node.config[SemanticsProperties.ToggleableState])
}
// WRONG because: bypasses the framework's error reporting. Failure prints a JUnit assertEquals
// diff with no node dump, no selector description, no hint about which screen the failure
// happened on.kotlin
// RIGHT
@Test
fun darkMode_switch_isOn() {
rule.setContent { SettingsScreen() }
rule.onNodeWithTag(DarkModeSwitchTag).assertIsOn()
}assertIsOnassert(isOn())Assertions.kt:74isOn()expectValue(SemanticsProperties.ToggleableState, ToggleableState.On)Filters.kt:61-62Pattern: assertTextEquals
(vararg) handles merged Text + EditableText
assertTextEquals模式:assertTextEquals
(vararg)可处理合并后的 Text + EditableText
assertTextEqualskotlin
// production:
TextField(value = "hello", onValueChange = {}, label = { Text("Name") },
modifier = Modifier.testTag(NameFieldTag))
// test:
rule.onNodeWithTag(NameFieldTag).assertTextEquals("Name", "hello")assertTextEquals(vararg)SemanticsProperties.TextSemanticsProperties.EditableTextAssertions.kt:181-185Filters.kt:274-293assertTextEquals("Name", includeEditableText = false)kotlin
// production:
TextField(value = "hello", onValueChange = {}, label = { Text("Name") },
modifier = Modifier.testTag(NameFieldTag))
// test:
rule.onNodeWithTag(NameFieldTag).assertTextEquals("Name", "hello")assertTextEquals(vararg)SemanticsProperties.TextSemanticsProperties.EditableTextAssertions.kt:181-185Filters.kt:274-293assertTextEquals("Name", includeEditableText = false)Pattern: assertCountEquals
instead of onAllNodes(...).onFirst().assertExists()
assertCountEqualsonAllNodes(...).onFirst().assertExists()模式:使用 assertCountEquals
,而不是 onAllNodes(...).onFirst().assertExists()
assertCountEqualsonAllNodes(...).onFirst().assertExists()kotlin
// WRONG
rule.onAllNodesWithTag(ItemTag).onFirst().assertExists()
// WRONG because: only proves there is at least one item. Drift to zero items causes
// "no node matched" instead of a count error; drift to many is silently accepted.kotlin
// RIGHT
rule.onAllNodesWithTag(ItemTag).assertCountEquals(3)kotlin
// WRONG
rule.onAllNodesWithTag(ItemTag).onFirst().assertExists()
// WRONG because: only proves there is at least one item. Drift to zero items causes
// "no node matched" instead of a count error; drift to many is silently accepted.kotlin
// RIGHT
rule.onAllNodesWithTag(ItemTag).assertCountEquals(3)Pattern: assert(matcher)
for properties without a typed assertion
assert(matcher)模式:对没有类型化断言的属性使用 assert(matcher)
assert(matcher)kotlin
@Test
fun row_hasPriorityOne() {
rule.setContent { TaskList(tasks = tasks) }
rule.onNodeWithTag(TaskRowTag)
.assert(SemanticsMatcher.expectValue(PriorityKey, 1))
}PriorityKeySemanticsPropertyKey<Int>Modifier.semantics { priority = … }../../finders/composing-semantics-matchers/SKILL.mdkotlin
@Test
fun row_hasPriorityOne() {
rule.setContent { TaskList(tasks = tasks) }
rule.onNodeWithTag(TaskRowTag)
.assert(SemanticsMatcher.expectValue(PriorityKey, 1))
}PriorityKeyModifier.semantics { priority = … }SemanticsPropertyKey<Int>../../finders/composing-semantics-matchers/SKILL.mdPattern: assertAny
(fails on empty) vs assertAll
(passes on empty)
assertAnyassertAll模式:assertAny
(空集合时失败)与 assertAll
(空集合时通过)
assertAnyassertAllkotlin
// "at least one row is selected" — must have at least one row
rule.onAllNodesWithTag(RowTag).assertAny(isSelected())
// "every row is enabled" — accepts zero rows (passes vacuously)
rule.onAllNodesWithTag(RowTag).assertAll(isEnabled())assertAnyAssertionError("Failed to assertAny … no node matched")Assertions.kt:305-307assertAllAssertions.kt:323-339kotlin
// "at least one row is selected" — must have at least one row
rule.onAllNodesWithTag(RowTag).assertAny(isSelected())
// "every row is enabled" — accepts zero rows (passes vacuously)
rule.onAllNodesWithTag(RowTag).assertAll(isEnabled())assertAnyAssertionError("Failed to assertAny … no node matched")Assertions.kt:305-307assertAllAssertions.kt:323-339Pattern: isDisplayed()
inside waitUntil
isDisplayed()waitUntil模式:在 waitUntil
中使用 isDisplayed()
waitUntilisDisplayed()kotlin
// WRONG
rule.waitUntil { rule.onNodeWithTag(SnackbarTag).assertIsDisplayed(); true }
// WRONG because: assertIsDisplayed throws on the first poll where the snackbar isn't yet
// shown. waitUntil expects a boolean — predicates that throw will fail-fast.kotlin
// RIGHT
rule.waitUntil(timeoutMillis = 2_000) {
rule.onAllNodesWithTag(SnackbarTag).fetchSemanticsNodes().isNotEmpty() &&
rule.onNodeWithTag(SnackbarTag).isDisplayed()
}
rule.onNodeWithTag(SnackbarTag).assertTextContains("Saved")isDisplayed()falseAssertions.kt:343-351../../synchronization/synchronizing-with-idle/SKILL.mdwaitUntilmainClock.advanceTimeUntilkotlin
// WRONG
rule.waitUntil { rule.onNodeWithTag(SnackbarTag).assertIsDisplayed(); true }
// WRONG because: assertIsDisplayed throws on the first poll where the snackbar isn't yet
// shown. waitUntil expects a boolean — predicates that throw will fail-fast.kotlin
// RIGHT
rule.waitUntil(timeoutMillis = 2_000) {
rule.onAllNodesWithTag(SnackbarTag).fetchSemanticsNodes().isNotEmpty() &&
rule.onNodeWithTag(SnackbarTag).isDisplayed()
}
rule.onNodeWithTag(SnackbarTag).assertTextContains("Saved")当没有节点匹配时, 返回 ;只有匹配到多个节点时才会抛出异常()。有关 与 的区别,请交叉参考 。
isDisplayed()falseAssertions.kt:343-351waitUntilmainClock.advanceTimeUntil../../synchronization/synchronizing-with-idle/SKILL.mdPattern: assertIsDeactivated
for SubcomposeLayout retained children
assertIsDeactivated模式:使用 assertIsDeactivated
验证 SubcomposeLayout 保留的子项
assertIsDeactivatedkotlin
// LookaheadLayout / SubcomposeLayout may retain a previously composed slot for reuse.
// To verify the slot is currently deactivated (kept, not active):
rule.onNodeWithTag(RetainedSlotTag).assertIsDeactivated()assertIsDeactivatedSemanticsNodeInteraction.kt:137-148node.layoutInfo.isDeactivatedkotlin
// LookaheadLayout / SubcomposeLayout may retain a previously composed slot for reuse.
// To verify the slot is currently deactivated (kept, not active):
rule.onNodeWithTag(RetainedSlotTag).assertIsDeactivated()assertIsDeactivatedSemanticsNodeInteraction.kt:137-148node.layoutInfo.isDeactivatedMandatory rules
强制规则
- MUST use the typed assertion (,
assertIsOn,assertIsEnabled, …) overassertTextEquals. The framework's error message includes the selector, the node dump, and the failed clause.fetchSemanticsNode().config[...] - MUST use when the contract is "the user sees this"; MUST use
assertIsDisplayed()only when the contract is "this is in the semantics tree" (e.g. checking presence in unmerged tree without on-screen requirement).assertExists() - MUST use the boolean /
isDisplayed()insideisNotDisplayed()blocks; MUST NOT call throwingwaitUntil { … }from insideassertIs*.waitUntil - MUST use for collection cardinality; MUST NOT index
assertCountEqualsto imply "the only one".[0] - MUST NOT repeat the same assertion across chained calls when one composed matcher would do — see .
../../finders/composing-semantics-matchers/SKILL.md - PREFERRED: prefer tag-anchored lookups before assertions. Skydoves hot take #1.
- 必须使用类型化断言(、
assertIsOn、assertIsEnabled等),而不是assertTextEquals。框架的错误信息包含 selector、节点转储和失败的断言条件。fetchSemanticsNode().config[...] - 当契约要求“用户可以看到它”时,必须使用 ;只有当契约要求“它存在于 semantics 树中”时,才使用
assertIsDisplayed()(例如检查未合并树中的存在性,而不考虑是否位于屏幕上)。assertExists() - 在 块中,必须使用布尔型
waitUntil { … }/isDisplayed();不得在isNotDisplayed()中调用会抛出异常的waitUntil。assertIs* - 必须使用 检查集合基数;不得通过索引
assertCountEquals暗示“只有这一个”。[0] - 当一个组合后的 matcher 可以完成检查时,不得在链式调用中重复相同断言——参见 。
../../finders/composing-semantics-matchers/SKILL.md - **优先:**在断言之前使用以 tag 为锚点的查找。Skydoves 热门观点 #1。
Verification
验证
- No assertion reads directly. All property checks go through
node.config[...]/assertIs*/assertTextEquals.assert(matcher) - is used for user-visible checks;
assertIsDisplayedonly when on-screen visibility is irrelevant.assertExists - blocks use
waitUntil { … }/isDisplayed()/isNotDisplayed()— no throwingfetchSemanticsNodes().sizecalls inside.assertIs* - /
assertAnychoice matches the intended empty-collection semantics.assertAll - (device) or
./gradlew :app:connectedDebugAndroidTest(host) passes.:app:testDebugUnitTest - Failure messages mention the offending semantic property by name (proof the typed assertion is in use).
- 没有断言直接读取 。所有属性检查都通过
node.config[...]/assertIs*/assertTextEquals完成。assert(matcher) - 用户可见性检查使用 ;只有不关心是否位于屏幕上时才使用
assertIsDisplayed。assertExists - 块使用
waitUntil { … }/isDisplayed()/isNotDisplayed(),不包含会抛出异常的fetchSemanticsNodes().size调用。assertIs* - /
assertAny的选择符合预期的空集合语义。assertAll - (设备)或
./gradlew :app:connectedDebugAndroidTest(主机)通过。:app:testDebugUnitTest - 错误信息会指出发生问题的 semantics 属性名称,证明使用的是类型化断言。
References
参考资料
- Compose testing overview: https://developer.android.com/develop/ui/compose/testing
- Compose testing cheat sheet: https://developer.android.com/develop/ui/compose/testing-cheatsheet
- Semantics in Compose: https://developer.android.com/develop/ui/compose/accessibility/semantics
- — every
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Assertions.kt/assertIs*/assertTextEquals/assertContentDescriptionEquals/assertHasClickAction/assertCountEquals/assertAll/assertAny/isDisplayed.isNotDisplayed - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/SemanticsNodeInteraction.kt,assertExists,assertDoesNotExist,assertIsDeactivated.fetchSemanticsNode - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Filters.kt,isOn,isEnabled,hasTextunderlying matchers used by typed assertions.hasClickAction
- Compose 测试概览:https://developer.android.com/develop/ui/compose/testing
- Compose 测试速查表:https://developer.android.com/develop/ui/compose/testing-cheatsheet
- Compose 中的 Semantics:https://developer.android.com/develop/ui/compose/accessibility/semantics
- ——包含所有
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Assertions.kt/assertIs*/assertTextEquals/assertContentDescriptionEquals/assertHasClickAction/assertCountEquals/assertAll/assertAny/isDisplayed。isNotDisplayed - ——包含
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/SemanticsNodeInteraction.kt、assertExists、assertDoesNotExist、assertIsDeactivated。fetchSemanticsNode - ——包含类型化断言底层使用的
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Filters.kt、isOn、isEnabled、hasTextmatcher。hasClickAction