entering-text
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEntering Text — performTextInput, performTextReplacement, performImeAction
输入文本——performTextInput、performTextReplacement、performImeAction
Compose text fields expose semantics actions for IME-style edits. The test API wraps those actions so a single call types text, replaces text, clears text, sets a selection, or fires the IME action. Every entry point auto-focuses the node when needed and asserts that the node is enabled and editable, surfacing precise errors when one of those preconditions fails.
Compose 文本输入框暴露了用于 IME 风格编辑的 semantics actions。测试 API 对这些操作进行了封装,因此只需一次调用即可输入文本、替换文本、清除文本、设置选区或触发 IME action。每个入口都会在必要时自动聚焦节点,并断言节点已启用且可编辑;当前置条件不满足时,会给出精确的错误信息。
When to use this skill
何时使用此 skill
- The test types into ,
TextField,OutlinedTextField, or any composable that exposes theBasicTextField/InsertTextAtCursorsemantics actions.SetText - The test fires an IME action — to advance focus,
ImeAction.Nextto dismiss the keyboard,ImeAction.Done/ImeAction.Search/Sendto trigger a form submit.Go - The test must clear an existing value, or replace the full value with new text.
- The test asserts cursor or selection state with .
performTextInputSelection(TextRange(...))
- 测试需要向 、
TextField、OutlinedTextField或任何暴露BasicTextField/InsertTextAtCursorsemantics actions 的 composable 中输入文本。SetText - 测试需要触发 IME action,例如使用 移动焦点、使用
ImeAction.Next收起键盘,或使用ImeAction.Done/ImeAction.Search/Send触发表单提交。Go - 测试需要清除已有值,或使用新文本替换完整值。
- 测试需要通过 断言光标或选区状态。
performTextInputSelection(TextRange(...))
When NOT to use this skill
何时不应使用此 skill
- The test sends an arbitrary key shortcut into a focused field (e.g. ,
Ctrl+A, arrow keys). UseTab.../injecting-mouse-and-keyboard/SKILL.md - The test only checks the displayed text without typing — assert via .
../../assertions/asserting-node-state-and-text/SKILL.md - A finder cannot locate the text field. Verify the matcher first via .
../../finders/finding-nodes-by-tag-text-content/SKILL.md - The test asserts state restoration of the typed text after rotation. See and
../../setup/configuring-test-dependencies/SKILL.md.StateRestorationTester
- 测试需要向已聚焦的输入框发送任意快捷键(例如 、
Ctrl+A、方向键)。请使用Tab。../injecting-mouse-and-keyboard/SKILL.md - 测试只检查显示的文本而不执行输入——请通过 进行断言。
../../assertions/asserting-node-state-and-text/SKILL.md - finder 无法定位到文本输入框。请先通过 验证 matcher。
../../finders/finding-nodes-by-tag-text-content/SKILL.md - 测试需要断言旋转屏幕后输入文本的状态恢复。请参阅 和
../../setup/configuring-test-dependencies/SKILL.md。StateRestorationTester
Prerequisites
前置条件
- (or
androidx.compose.ui:ui-test-junit4forui-test) configured perrunComposeUiTest.../../setup/configuring-test-dependencies/SKILL.md - The carries
TextFieldfrom production code so the test selects it deterministically.Modifier.testTag("…") - The field is .
enabled = truecallsperformTextInputbefore doing anything (TextActions.kt:125).assert(isEnabled()) - For : the field declares both
performImeAction(viaImeAction != ImeAction.Default) and anKeyboardOptions(imeAction = …)handler (viaOnImeActionor default keyboard actions). The action assertion checks both (TextActions.kt:99-100).KeyboardActions(...)
- 已按 配置
../../setup/configuring-test-dependencies/SKILL.md(或用于androidx.compose.ui:ui-test-junit4的runComposeUiTest)。ui-test - 在生产代码中带有
TextField,以便测试确定性地选择该节点。Modifier.testTag("…") - 输入框的 。
enabled = true在执行任何操作前会调用performTextInput(TextActions.kt:125)。assert(isEnabled()) - 对于 :输入框必须同时声明非默认的
performImeAction(通过ImeAction != ImeAction.Default)和KeyboardOptions(imeAction = …)处理器(通过OnImeAction或默认键盘操作)。action 断言会同时检查这两项(TextActions.kt:99-100)。KeyboardActions(...)
Workflow
工作流
- Type text at the cursor — (TextActions.kt:37-41). Internally invokes
performTextInput(text)withSemanticsActions.InsertTextAtCursor. Auto-focuses the node first when it is not focused (AnnotatedString(text)— TextActions.kt:119-138). ThrowsgetNodeAndFocusif the node is not enabled, not focusable, or does not advertiseAssertionError("Failed to perform text input.").InsertTextAtCursor
kotlin
rule.onNodeWithTag(Tag).performTextInput("Hello ")- Replace the entire text — (TextActions.kt:81-84). Invokes
performTextReplacement(text), which clears existing text and inserts new text. Use this when the field already has a value the test wants to overwrite. MUST NOT be used to "type more characters" — see the WRONG/RIGHT pair below.SemanticsActions.SetText
kotlin
rule.onNodeWithTag(Tag).performTextReplacement("New value")- Clear the text — (TextActions.kt:28-30). Sugar for
performTextClearance(). The field must be focusable + haveperformTextReplacement("").SetText
kotlin
rule.onNodeWithTag(Tag).performTextClearance()- Set the selection / cursor — (TextActions.kt:61-72). Maps to
performTextInputSelection(selection: TextRange, relativeToOriginalText: Boolean = true). WhenSemanticsActions.SetSelection, indices refer to the original (untransformed) text;relativeToOriginalText = truemakes them refer to the post-falsetext.VisualTransformation
kotlin
rule.onNodeWithTag(Tag).performTextInput("Hello World")
rule.onNodeWithTag(Tag).performTextInputSelection(TextRange(0, 5)) // selects "Hello"- Fire the IME action — (TextActions.kt:97-117). Pre-conditions, in order:
performImeAction()- — the field declares
assert(hasPerformImeAction()).OnImeAction - — the action is something other than the default.
assert(!hasImeAction(ImeAction.Default)) - .
tryPerformAccessibilityChecks() - Auto-focus via .
getNodeAndFocus(requireEditable = false) - Invoke and require it returned
OnImeAction; otherwise throwtrue.AssertionError("Failed to perform IME action, handler returned false.")
kotlin
rule.onNodeWithTag(InitialFieldTag).performImeAction()- Pair with to confirm the expected post-state. The merged-tree default applies to text assertions exactly as to finders — see
assertTextEquals.../../assertions/asserting-node-state-and-text/SKILL.md
- 在光标处输入文本——(TextActions.kt:37-41)。内部使用
performTextInput(text)调用AnnotatedString(text)。当节点尚未获得焦点时,会先自动聚焦(SemanticsActions.InsertTextAtCursor——TextActions.kt:119-138)。如果节点未启用、不可聚焦,或未提供getNodeAndFocus,则抛出InsertTextAtCursor。AssertionError("Failed to perform text input.")
kotlin
rule.onNodeWithTag(Tag).performTextInput("Hello ")- 替换全部文本——(TextActions.kt:81-84)。调用
performTextReplacement(text),清除已有文本并插入新文本。当输入框已包含测试希望覆盖的值时,应使用此方法。不得将其用于“继续输入更多字符”——请参阅下方错误/正确示例。SemanticsActions.SetText
kotlin
rule.onNodeWithTag(Tag).performTextReplacement("New value")- 清除文本——(TextActions.kt:28-30)。这是
performTextClearance()的语法糖。输入框必须可聚焦并提供performTextReplacement("")。SetText
kotlin
rule.onNodeWithTag(Tag).performTextClearance()- 设置选区或光标——(TextActions.kt:61-72)。映射到
performTextInputSelection(selection: TextRange, relativeToOriginalText: Boolean = true)。当SemanticsActions.SetSelection时,索引指向原始、未经转换的文本;当其为relativeToOriginalText = true时,索引指向应用false后的文本。VisualTransformation
kotlin
rule.onNodeWithTag(Tag).performTextInput("Hello World")
rule.onNodeWithTag(Tag).performTextInputSelection(TextRange(0, 5)) // selects "Hello"- 触发 IME action——(TextActions.kt:97-117)。按顺序检查以下前置条件:
performImeAction()- ——输入框声明了
assert(hasPerformImeAction())。OnImeAction - ——action 不是默认值。
assert(!hasImeAction(ImeAction.Default)) - 。
tryPerformAccessibilityChecks() - 通过 自动聚焦。
getNodeAndFocus(requireEditable = false) - 调用 ,并要求其返回
OnImeAction;否则抛出true。AssertionError("Failed to perform IME action, handler returned false.")
kotlin
rule.onNodeWithTag(InitialFieldTag).performImeAction()- 与 配合使用,以确认预期的操作后状态。merged-tree 默认行为对文本断言的生效方式与对 finders 的生效方式完全相同——请参阅
assertTextEquals。../../assertions/asserting-node-state-and-text/SKILL.md
Patterns
模式
Pattern: Append (performTextInput
) vs replace (performTextReplacement
)
performTextInputperformTextReplacement模式:追加(performTextInput
)与替换(performTextReplacement
)
performTextInputperformTextReplacementThe most common gotcha — the two APIs look interchangeable but compose differently.
kotlin
// WRONG
rule.onNodeWithTag(Tag).performTextInput("hello")
rule.onNodeWithTag(Tag).performTextInput("world")
rule.onNodeWithTag(Tag).assertTextEquals("world")
// WRONG because: performTextInput maps to InsertTextAtCursor, not SetText. The cursor
// remains at the end of "hello" after the first call, so the second call inserts
// "world" there. Final value is "helloworld" — assertion fails.kotlin
// RIGHT
rule.onNodeWithTag(Tag).performTextInput("hello")
rule.onNodeWithTag(Tag).performTextReplacement("world")
rule.onNodeWithTag(Tag).assertTextEquals("world")performTextReplacementSemanticsActions.SetText这是最常见的陷阱——两个 API 看起来可以互换,但实现方式不同。
kotlin
// WRONG
rule.onNodeWithTag(Tag).performTextInput("hello")
rule.onNodeWithTag(Tag).performTextInput("world")
rule.onNodeWithTag(Tag).assertTextEquals("world")
// WRONG because: performTextInput maps to InsertTextAtCursor, not SetText. The cursor
// remains at the end of "hello" after the first call, so the second call inserts
// "world" there. Final value is "helloworld" — assertion fails.kotlin
// RIGHT
rule.onNodeWithTag(Tag).performTextInput("hello")
rule.onNodeWithTag(Tag).performTextReplacement("world")
rule.onNodeWithTag(Tag).assertTextEquals("world")performTextReplacementSemanticsActions.SetTextPattern: Canonical insert + assert
模式:标准插入与断言
From :
BasicTextFieldTest.kt:171-194kotlin
@Test
fun textFieldState_textChange_updatesState() {
val state = TextFieldState("Hello ", TextRange(Int.MAX_VALUE))
inputMethodInterceptor.setTextFieldTestContent {
BasicTextField(state = state, modifier = Modifier.fillMaxSize().testTag(Tag))
}
rule.onNodeWithTag(Tag).performTextInput("World!")
rule.runOnIdle { assertThat(state.text.toString()).isEqualTo("Hello World!") }
}
@Test
fun textFieldState_textChange_updatesSemantics() {
val state = TextFieldState("Hello ", TextRange(Int.MAX_VALUE))
inputMethodInterceptor.setTextFieldTestContent {
BasicTextField(state = state, modifier = Modifier.fillMaxSize().testTag(Tag))
}
rule.onNodeWithTag(Tag).performTextInput("World!")
rule.onNodeWithTag(Tag).assertTextEquals("Hello World!")
}The cursor is positioned at (end of text) when constructing . inserts at that cursor — final value . State reads happen inside (skydoves hot take #5).
TextRange(Int.MAX_VALUE)TextFieldStateperformTextInput("World!")"Hello World!"runOnIdle摘自 :
BasicTextFieldTest.kt:171-194kotlin
@Test
fun textFieldState_textChange_updatesState() {
val state = TextFieldState("Hello ", TextRange(Int.MAX_VALUE))
inputMethodInterceptor.setTextFieldTestContent {
BasicTextField(state = state, modifier = Modifier.fillMaxSize().testTag(Tag))
}
rule.onNodeWithTag(Tag).performTextInput("World!")
rule.runOnIdle { assertThat(state.text.toString()).isEqualTo("Hello World!") }
}
@Test
fun textFieldState_textChange_updatesSemantics() {
val state = TextFieldState("Hello ", TextRange(Int.MAX_VALUE))
inputMethodInterceptor.setTextFieldTestContent {
BasicTextField(state = state, modifier = Modifier.fillMaxSize().testTag(Tag))
}
rule.onNodeWithTag(Tag).performTextInput("World!")
rule.onNodeWithTag(Tag).assertTextEquals("Hello World!")
}构造 时,光标位于 (文本末尾)。 会在该光标位置插入——最终值为 。状态读取必须在 中进行(skydoves hot take #5)。
TextFieldStateTextRange(Int.MAX_VALUE)performTextInput("World!")"Hello World!"runOnIdlePattern: Replace then assert — BasicTextFieldTest.kt:442-466
BasicTextFieldTest.kt:442-466模式:替换后断言——BasicTextFieldTest.kt:442-466
BasicTextFieldTest.kt:442-466kotlin
@Test
fun textField_whenStateObjectChanges_restartsInput() {
val state1 = TextFieldState("Hello")
val state2 = TextFieldState("World")
var toggleState by mutableStateOf(true)
val state by derivedStateOf { if (toggleState) state1 else state2 }
inputMethodInterceptor.setTextFieldTestContent {
BasicTextField(
state = state,
enabled = true,
modifier = Modifier.fillMaxSize().testTag(Tag),
)
}
with(rule.onNodeWithTag(Tag)) {
performTextReplacement("Compose")
assertTextEquals("Compose")
}
toggleState = !toggleState
with(rule.onNodeWithTag(Tag)) {
performTextReplacement("Compose2")
assertTextEquals("Compose2")
}
assertThat(state1.text.toString()).isEqualTo("Compose")
assertThat(state2.text.toString()).isEqualTo("Compose2")
}performTextReplacementkotlin
@Test
fun textField_whenStateObjectChanges_restartsInput() {
val state1 = TextFieldState("Hello")
val state2 = TextFieldState("World")
var toggleState by mutableStateOf(true)
val state by derivedStateOf { if (toggleState) state1 else state2 }
inputMethodInterceptor.setTextFieldTestContent {
BasicTextField(
state = state,
enabled = true,
modifier = Modifier.fillMaxSize().testTag(Tag),
)
}
with(rule.onNodeWithTag(Tag)) {
performTextReplacement("Compose")
assertTextEquals("Compose")
}
toggleState = !toggleState
with(rule.onNodeWithTag(Tag)) {
performTextReplacement("Compose2")
assertTextEquals("Compose2")
}
assertThat(state1.text.toString()).isEqualTo("Compose")
assertThat(state2.text.toString()).isEqualTo("Compose2")
}performTextReplacementPattern: Clearing then refilling
模式:清除后重新输入
kotlin
rule.onNodeWithTag(Tag).performTextClearance()
rule.onNodeWithTag(Tag).performTextInput("Different")
rule.onNodeWithTag(Tag).assertTextEquals("Different")performTextClearanceperformTextReplacement("")performTextInputkotlin
rule.onNodeWithTag(Tag).performTextClearance()
rule.onNodeWithTag(Tag).performTextInput("Different")
rule.onNodeWithTag(Tag).assertTextEquals("Different")performTextClearanceperformTextReplacement("")performTextInputPattern: IME-action focus chain (Next
advances focus)
Next模式:IME action 焦点链(Next
移动焦点)
NextFrom :
DefaultKeyboardActionsTest.kt:130-149kotlin
// Show keyboard.
rule.onNodeWithTag(initialTextField).performClick()
inputMethodInterceptor.assertSessionActive()
keyboardController.show()
// Act.
rule.onNodeWithTag(initialTextField).performImeAction()
// Assert.
when (imeAction) {
Next -> {
// Focus moves to the next item.
assertThat(focusState1).isFalse()
assertThat(focusState2).isFalse()
assertThat(focusState3).isTrue()
}
Previous -> {
// Focus moves to the previous item.
assertThat(focusState1).isTrue()
assertThat(focusState2).isFalse()
assertThat(focusState3).isFalse()
}
Done -> {
// No change to focus state.
assertThat(focusState1).isFalse()
assertThat(focusState2).isTrue()
assertThat(focusState3).isFalse()
// Software keyboard is hidden.
keyboardController.assertHidden()
}
}Production must declare a non-default for to be valid:
ImeActionperformImeActionkotlin
BasicTextField(
state = state,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
modifier = Modifier.testTag(InitialFieldTag),
)performImeAction!hasImeAction(ImeAction.Default)keyboardOptionsAssertionError("Failed to perform IME action.")摘自 :
DefaultKeyboardActionsTest.kt:130-149kotlin
// Show keyboard.
rule.onNodeWithTag(initialTextField).performClick()
inputMethodInterceptor.assertSessionActive()
keyboardController.show()
// Act.
rule.onNodeWithTag(initialTextField).performImeAction()
// Assert.
when (imeAction) {
Next -> {
// Focus moves to the next item.
assertThat(focusState1).isFalse()
assertThat(focusState2).isFalse()
assertThat(focusState3).isTrue()
}
Previous -> {
// Focus moves to the previous item.
assertThat(focusState1).isTrue()
assertThat(focusState2).isFalse()
assertThat(focusState3).isFalse()
}
Done -> {
// No change to focus state.
assertThat(focusState1).isFalse()
assertThat(focusState2).isTrue()
assertThat(focusState3).isFalse()
// Software keyboard is hidden.
keyboardController.assertHidden()
}
}生产代码必须声明非默认的 , 才能有效执行:
ImeActionperformImeActionkotlin
BasicTextField(
state = state,
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
modifier = Modifier.testTag(InitialFieldTag),
)performImeAction!hasImeAction(ImeAction.Default)keyboardOptionsAssertionError("Failed to perform IME action.")Pattern: Set selection before replacing a substring
模式:替换子字符串前设置选区
kotlin
rule.onNodeWithTag(Tag).performTextInput("Hello World")
rule.onNodeWithTag(Tag).performTextInputSelection(TextRange(6, 11)) // select "World"
rule.onNodeWithTag(Tag).performTextInput("Compose") // selection replaced
rule.onNodeWithTag(Tag).assertTextEquals("Hello Compose")SemanticsActions.SetSelectionInsertTextAtCursorrelativeToOriginalText = falseVisualTransformationkotlin
rule.onNodeWithTag(Tag).performTextInput("Hello World")
rule.onNodeWithTag(Tag).performTextInputSelection(TextRange(6, 11)) // select "World"
rule.onNodeWithTag(Tag).performTextInput("Compose") // selection replaced
rule.onNodeWithTag(Tag).assertTextEquals("Hello Compose")SemanticsActions.SetSelectionInsertTextAtCursorVisualTransformationrelativeToOriginalText = falsePattern: Disabled or non-editable field — clear error
模式:禁用或不可编辑的输入框——清晰的错误信息
If the field is or the matcher resolves to a instead of a , throws . The chain is:
enabled = falseTextTextFieldperformTextInputAssertionError("Failed to perform text input.")- .
tryPerformAccessibilityChecks() - .
assert(isEnabled()) - .
assert(hasRequestFocusAction()) - and
assert(hasSetTextAction())(TextActions.kt:127-129).assert(hasInsertTextAtCursorAction())
When the assertion fires, dump the semantics tree via to confirm the matcher is not selecting a static .
../../debug/printing-the-semantics-tree/SKILL.mdText如果输入框的 ,或者 matcher 解析到的是 而非 , 会抛出 。检查链如下:
enabled = falseTextTextFieldperformTextInputAssertionError("Failed to perform text input.")- 。
tryPerformAccessibilityChecks() - 。
assert(isEnabled()) - 。
assert(hasRequestFocusAction()) - 和
assert(hasSetTextAction())(TextActions.kt:127-129)。assert(hasInsertTextAtCursorAction())
断言触发后,请通过 输出 semantics tree,以确认 matcher 没有选中静态 。
../../debug/printing-the-semantics-tree/SKILL.mdTextMandatory rules
强制规则
- MUST use to overwrite an existing value. MUST NOT chain two
performTextReplacementcalls expecting the second to replace the first — they concatenate at the cursor.performTextInput - MUST declare a non-default (e.g.
ImeAction) before callingKeyboardOptions(imeAction = ImeAction.Next). The API assertsperformImeAction(TextActions.kt:100) and throws otherwise.!hasImeAction(ImeAction.Default) - MUST select the field by whose value is a constant in production code — skydoves hot take #1.
Modifier.testTag(...) - MUST route post-input state assertions through (skydoves hot take #5). The recomposer needs to settle before reading
rule.runOnIdle { … }.TextFieldState.text - MUST NOT call to wait for IME events. Compose's idle observation includes the text-input pipeline; the assertion will be ready when
Thread.sleepreturns.runOnIdle - MUST NOT simulate text entry by injecting individual events through
Keyunless the test specifically exercises the hardware-keyboard path. The semantics actions are the canonical IME path.performKeyInput { pressKey(Key.A) } - PREFERRED: keep calls explicit about
performTextInputSelection. The default (relativeToOriginalText) is correct for most cases; flip it only when the field installs atrue.VisualTransformation
- 必须使用 覆盖已有值。不得连续调用两次
performTextReplacement并期望第二次调用替换第一次的内容——它们会在光标处拼接。performTextInput - 必须在调用 前声明非默认的
performImeAction(例如ImeAction)。该 API 会断言KeyboardOptions(imeAction = ImeAction.Next)(TextActions.kt:100),否则将抛出异常。!hasImeAction(ImeAction.Default) - 必须使用 选择输入框,并且该标签值应为生产代码中的常量——skydoves hot take #1。
Modifier.testTag(...) - 必须通过 执行输入操作后的状态断言(skydoves hot take #5)。读取
rule.runOnIdle { … }前,需要等待 recomposer 稳定下来。TextFieldState.text - 不得调用 等待 IME 事件。Compose 的 idle observation 已包含 text-input pipeline;当
Thread.sleep返回时,断言所需状态已经就绪。runOnIdle - 不得通过 注入单个
performKeyInput { pressKey(Key.A) }事件来模拟文本输入,除非测试明确需要验证硬件键盘路径。semantics actions 才是标准的 IME 路径。Key - **推荐:**明确指定 调用中的
performTextInputSelection。大多数情况下应使用默认值(relativeToOriginalText);仅当输入框安装了true时才调整。VisualTransformation
Verification
验证
- Every test that overwrites field content uses or
performTextReplacement(...)followed byperformTextClearance(). No back-to-backperformTextInput(...)calls expecting replacement semantics.performTextInput - Every call targets a field that declares
performImeActionin production source.KeyboardOptions(imeAction = ImeAction.Next | Done | Search | …) - State or text assertions following an input action run inside .
rule.runOnIdle { … } - No in the test method.
Thread.sleep - (or
./gradlew :app:connectedDebugAndroidTestfor Robolectric) passes for the test under change.:app:testDebugUnitTest
- 每个覆盖输入框内容的测试都使用 ,或先调用
performTextReplacement(...)再调用performTextClearance()。不存在连续调用performTextInput(...)并期望产生替换语义的情况。performTextInput - 每个 调用都指向在生产代码中声明了
performImeAction的输入框。KeyboardOptions(imeAction = ImeAction.Next | Done | Search | …) - 输入 action 后的状态或文本断言均在 中运行。
rule.runOnIdle { … } - 测试方法中不存在 。
Thread.sleep - (或使用 Robolectric 时执行
./gradlew :app:connectedDebugAndroidTest)能够通过本次修改涉及的测试。:app:testDebugUnitTest
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
- BasicTextField docs: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/package-summary#BasicTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.KeyboardActions,kotlin.Boolean,kotlin.Int,kotlin.Int,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.graphics.SolidColor,androidx.compose.foundation.text.input.OutputTransformation,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.text.input.TextFieldDecorator)
- —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/TextActions.kt(TextActions.kt:28),performTextClearance(TextActions.kt:37),performTextInput(TextActions.kt:61),performTextInputSelection(TextActions.kt:81),performTextReplacement(TextActions.kt:97),performImeActionprecondition chain (TextActions.kt:119-138).getNodeAndFocus - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Filters.kt,hasPerformImeAction,hasImeAction,hasSetTextAction,hasInsertTextAtCursorAction,isEnabled.hasRequestFocusAction - — canonical
compose/foundation/foundation/src/androidDeviceTest/.../BasicTextFieldTest.kt+performTextInput(BasicTextFieldTest.kt:171-194),assertTextEquals(BasicTextFieldTest.kt:442-466).performTextReplacement - —
compose/foundation/foundation/src/androidDeviceTest/.../DefaultKeyboardActionsTest.kt+ IME-action focus chain (DefaultKeyboardActionsTest.kt:130-149).performImeAction - skydoves — compose-performance-skills: https://github.com/skydoves/compose-performance-skills
- Compose 测试概览:https://developer.android.com/develop/ui/compose/testing
- Compose 测试速查表:https://developer.android.com/develop/ui/compose/testing-cheatsheet
- BasicTextField 文档:https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/package-summary#BasicTextField(androidx.compose.foundation.text.input.TextFieldState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.compose.ui.text.TextStyle,androidx.compose.foundation.text.KeyboardOptions,androidx.compose.foundation.text.KeyboardActions,kotlin.Boolean,kotlin.Int,kotlin.Int,androidx.compose.foundation.text.input.InputTransformation,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.SolidColor,androidx.compose.foundation.text.input.OutputTransformation,androidx.compose.ui.interaction.MutableInteractionSource,androidx.compose.foundation.text.input.TextFieldDecorator)
- ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/TextActions.kt(TextActions.kt:28)、performTextClearance(TextActions.kt:37)、performTextInput(TextActions.kt:61)、performTextInputSelection(TextActions.kt:81)、performTextReplacement(TextActions.kt:97)、performImeAction前置条件链(TextActions.kt:119-138)。getNodeAndFocus - ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Filters.kt、hasPerformImeAction、hasImeAction、hasSetTextAction、hasInsertTextAtCursorAction、isEnabled。hasRequestFocusAction - ——标准的
compose/foundation/foundation/src/androidDeviceTest/.../BasicTextFieldTest.kt+performTextInput(BasicTextFieldTest.kt:171-194)、assertTextEquals(BasicTextFieldTest.kt:442-466)。performTextReplacement - ——
compose/foundation/foundation/src/androidDeviceTest/.../DefaultKeyboardActionsTest.kt+ IME action 焦点链(DefaultKeyboardActionsTest.kt:130-149)。performImeAction - skydoves——compose-performance-skills:https://github.com/skydoves/compose-performance-skills