injecting-mouse-and-keyboard
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInjecting Mouse and Keyboard — performMouseInput, performKeyInput, performMultiModalInput
注入鼠标和键盘——performMouseInput、performKeyInput、performMultiModalInput
Mouse and keyboard input are first-class modalities in Compose tests. Each has its own injection scope and entry point, plus a shared that combines all of them inside one batched gesture (touch, mouse, key, rotary, trackpad, indirect pointer). Coordinates remain node-local — the same rules as touch — and the entire injection state survives across blocks on the same node.
performMultiModalInputperform.*Input在 Compose 测试中,鼠标和键盘输入都是一等输入模态。它们各自拥有独立的注入作用域和入口点,并共享一个 ,用于在一次批处理手势中组合所有输入方式(触摸、鼠标、按键、旋钮、触控板、间接指针)。坐标仍然是节点本地坐标——与触摸输入遵循相同规则——并且在同一节点的各个 块之间,整个注入状态都会持续保留。
performMultiModalInputperform.*InputWhen to use this skill
何时使用此 skill
- The test exercises a desktop or Compose Multiplatform UI that responds to clicks, hover, right-click, scroll wheel, or modifier keys.
- The test must drive a keyboard shortcut (e.g. ,
Ctrl+S, arrow-key navigation).Shift+Tab - The test must verify hover-only behaviour: tooltip pop, color change on , mouse-only ripple state.
Modifier.hoverable - The test simulates a drag-and-drop with a mouse pointer.
- The test must combine modalities — for example "hover at (x, y) then click and hold while pressing ".
Shift
- 测试操作的是会响应点击、悬停、右键、滚轮或修饰键的桌面端或 Compose Multiplatform UI。
- 测试必须驱动键盘快捷键(例如 、
Ctrl+S、方向键导航)。Shift+Tab - 测试必须验证仅由 hover 触发的行为:tooltip 弹出、的颜色变化、仅由鼠标触发的 ripple 状态。
Modifier.hoverable - 测试模拟使用鼠标指针进行拖放。
- 测试必须组合多种模态,例如“在 (x, y) 位置悬停,然后按住 的同时点击并保持”。
Shift
When NOT to use this skill
何时不应使用此 skill
- The interaction is a finger tap or drag — use . Mouse is not interchangeable with touch on Android device tests.
../injecting-touch-gestures/SKILL.md - A simple already routes through the right modality per platform — use
performClick().../clicking-and-scrolling/SKILL.md - The test types into a — use
TextField. Key input here is for shortcuts, not text entry.../entering-text/SKILL.md - The test waits for a hover-driven animation to settle — pause the clock first per .
../../synchronization/testing-animations-deterministically/SKILL.md
- 交互是手指点按或拖动——使用 。在 Android 设备测试中,鼠标不能与触摸等同看待。
../injecting-touch-gestures/SKILL.md - 简单的 已经会按平台选择正确的输入方式——使用
performClick()。../clicking-and-scrolling/SKILL.md - 测试需要向 输入文本——使用
TextField。这里的按键输入用于快捷键,而不是文本输入。../entering-text/SKILL.md - 测试需要等待由 hover 驱动的动画结束——先按照 暂停时钟。
../../synchronization/testing-animations-deterministically/SKILL.md
Prerequisites
前置条件
- (or
androidx.compose.ui:ui-test-junit4forui-test) configured perrunComposeUiTest.../../setup/configuring-test-dependencies/SKILL.md - For mouse hover events on Android: API level that supports hover (typically API 23+) — Robolectric host tests work but check .
@Config(minSdk = …) - For key input that targets a focusable node: the node must be focusable (e.g. wrapped in or
Modifier.focusable()). Otherwise key events route to the focused root.Modifier.focusRequester(...)
- 已按照 配置
../../setup/configuring-test-dependencies/SKILL.md(或用于androidx.compose.ui:ui-test-junit4的runComposeUiTest)。ui-test - 对于 Android 上的鼠标 hover 事件:需要支持 hover 的 API level(通常为 API 23+)——Robolectric 宿主测试可用,但需检查 。
@Config(minSdk = …) - 对于目标是可聚焦节点的按键输入:节点必须可聚焦(例如使用 或
Modifier.focusable()包装)。否则,按键事件会被路由到当前获得焦点的根节点。Modifier.focusRequester(...)
Workflow
工作流
Mouse: performMouseInput
鼠标:performMouseInput
-
Open a mouse scope —(Actions.kt:448-461). Like touch, events are batched and flushed when the block returns; recomposition cannot interleave inside the block.
performMouseInput(block: MouseInjectionScope.() -> Unit) -
Use node-local coordinates.is the node's top-left, identical to
(0, 0).TouchInjectionScopeextendsMouseInjectionScopesoInjectionScope,center,topLeft,bottomRightare all available (InjectionScope.kt:34-206).percentOffset(...) -
Pick the right helper. All in:
MouseInjectionScope.kt
| Helper | Default | What it does |
|---|---|---|
| primary click at center | press → 60 ms wait → release |
| secondary click at center | shorthand for |
| midway between min/max double-tap window | |
| same delays as double | three sequential clicks |
| | press, hold, release |
| 300 ms | streams move events along a linear path |
| relative form | — |
| arbitrary curve | — |
| primary drag | |
| vertical | streams scroll events |
-
Drop to low-level events when needed:
- /
press(button: MouseButton = Primary).release(button: MouseButton = Primary) - /
moveTo(position, delayMillis = eventPeriodMillis).moveBy(delta, delayMillis = eventPeriodMillis) - /
updatePointerTo(position)— adjust position without sending an event.updatePointerBy(delta) - /
enter(position)— explicit hover-enter / hover-exit.exit(position) - — single wheel tick.
scroll(delta, scrollWheel = Vertical) - — emit an
cancel(delayMillis).ACTION_CANCEL - — last known mouse position.
currentPosition: Offset
-
Referenceand
MouseButtonfromScrollWheel:Mouse.kt- ,
MouseButton.Primary,MouseButton.Secondary—MouseButton.Tertiary.expect value class MouseButton - ,
ScrollWheel.Vertical—ScrollWheel.Horizontal.value class ScrollWheel
-
打开鼠标作用域——(Actions.kt:448-461)。与触摸输入一样,事件会被批处理,并在块返回时统一提交;重组无法在块内部穿插执行。
performMouseInput(block: MouseInjectionScope.() -> Unit) -
使用节点本地坐标。是节点的左上角,与
(0, 0)完全相同。TouchInjectionScope继承MouseInjectionScope,因此可以使用InjectionScope、center、topLeft、bottomRight等全部能力(InjectionScope.kt:34-206)。percentOffset(...) -
选择正确的辅助方法。 均位于中:
MouseInjectionScope.kt
| 辅助方法 | 默认行为 | 作用 |
|---|---|---|
| 在中心执行主键点击 | 按下 → 等待 60 ms → 释放 |
| 在中心执行次键点击 | |
| 位于双击时间窗口最小值与最大值的中点 | |
| 与双击使用相同的延迟 | 连续执行三次点击 |
| 按住 | 按下、保持、释放 |
| 300 ms | 沿线性路径流式发送移动事件 |
| 相对位移形式 | — |
| 任意曲线 | — |
| 主键拖放 | |
| 垂直滚动 | 流式发送滚动事件 |
-
需要时下沉到低层级事件:
- /
press(button: MouseButton = Primary)。release(button: MouseButton = Primary) - /
moveTo(position, delayMillis = eventPeriodMillis)。moveBy(delta, delayMillis = eventPeriodMillis) - /
updatePointerTo(position)——仅调整位置,不发送事件。updatePointerBy(delta) - /
enter(position)——显式触发 hover 进入/退出。exit(position) - ——发送一次滚轮刻度事件。
scroll(delta, scrollWheel = Vertical) - ——发出一个
cancel(delayMillis)。ACTION_CANCEL - ——最后一个已知的鼠标位置。
currentPosition: Offset
-
从引用
Mouse.kt和MouseButton:ScrollWheel- 、
MouseButton.Primary、MouseButton.Secondary——MouseButton.Tertiary。expect value class MouseButton - 、
ScrollWheel.Vertical——ScrollWheel.Horizontal。value class ScrollWheel
Keyboard: performKeyInput
键盘:performKeyInput
-
Open a key scope —(Actions.kt:532-545).
performKeyInput(block: KeyInjectionScope.() -> Unit) -
Send key events. Core surface (KeyInjectionScope.kt:55-107):
- /
keyDown(key: Key)— primitives. ThrowkeyUp(key: Key)if state is invalid (already-down, already-up).IllegalStateException - — query injection state.
isKeyDown(key: Key): Boolean - Modifier-state vals: ,
isCtrlDown,isAltDown,isShiftDown,isMetaDown(KeyInjectionScope.kt:236-269),isFnDown,isCapsLockOn,isNumLockOn(KeyInjectionScope.kt:64-81). These reflect the injected state, not the host machine.isScrollLockOn
-
Use the helpers (KeyInjectionScope.kt:146-229):
- —
pressKey(key, pressDurationMillis = 50L).keyDown(key); advanceEventTime(50); keyUp(key) - — runs
withKeyDown(key) { … }whileblockis held; auto-releases inkey. The held key MUST NOT be used insidefinally.block - — same but multiple keys held simultaneously.
withKeysDown(listOf(key1, key2)) { … } - /
withKeyToggled(key) { … }—withKeysToggled(keys) { … }before and afterpressKey. Useful forblock,CapsLock,NumLock.ScrollLock
-
Repeat-key behavior. Holding a key down and advancing the event time (viafrom
advanceEventTime) produces repeat events: the first repeat fires after 500 ms, then every 50 ms (KeyInjectionScope.kt:43-50). This is NOT triggered byInjectionScope— that one advances the test clock, not the injection event time.MainTestClock.advanceTimeBy -
Direct KeyEvent injection —from
SemanticsNodeInteraction.performKeyPress(KeyEvent): Boolean. ReturnsKeyInputHelpers.kt:27if the event was consumed. Use it when you already have atrue(e.g. constructed viaKeyEventfor fine-grained source/scancode control); otherwise prefer the DSL.KeyEvent(NativeKeyEvent(...))
-
打开按键作用域——(Actions.kt:532-545)。
performKeyInput(block: KeyInjectionScope.() -> Unit) -
发送按键事件。 核心 API(KeyInjectionScope.kt:55-107):
- /
keyDown(key: Key)——基础操作。如果状态无效(按键已按下或已释放),会抛出keyUp(key: Key)。IllegalStateException - ——查询注入状态。
isKeyDown(key: Key): Boolean - 修饰键状态属性:、
isCtrlDown、isAltDown、isShiftDown、isMetaDown(KeyInjectionScope.kt:236-269),以及isFnDown、isCapsLockOn、isNumLockOn(KeyInjectionScope.kt:64-81)。这些属性反映的是注入状态,而不是宿主机器的状态。isScrollLockOn
-
使用辅助方法(KeyInjectionScope.kt:146-229):
- ——
pressKey(key, pressDurationMillis = 50L)。keyDown(key); advanceEventTime(50); keyUp(key) - ——在按住
withKeyDown(key) { … }的同时运行key;会在block中自动释放。在finally内不得再次使用这个处于按住状态的按键。block - ——与前者相同,但可同时按住多个按键。
withKeysDown(listOf(key1, key2)) { … } - /
withKeyToggled(key) { … }——在withKeysToggled(keys) { … }前后各执行一次block。适用于pressKey、CapsLock、NumLock。ScrollLock
-
按键重复行为。 按住某个键并推进事件时间(通过的
InjectionScope)会生成重复事件:首次重复在 500 ms 后触发,随后每 50 ms 触发一次(KeyInjectionScope.kt:43-50)。这不会由advanceEventTime触发——后者推进的是测试时钟,而不是注入事件时间。MainTestClock.advanceTimeBy -
直接注入 KeyEvent——(KeyInputHelpers.kt:27)。如果事件已被消费则返回
SemanticsNodeInteraction.performKeyPress(KeyEvent): Boolean。当已经拥有true时使用它(例如通过KeyEvent构造,以便精细控制 source/scancode);否则优先使用 DSL。KeyEvent(NativeKeyEvent(...))
Multi-modal: performMultiModalInput
多模态:performMultiModalInput
-
Open a multi-modal scope —(Actions.kt:582-594).
performMultiModalInput(block: MultiModalInjectionScope.() -> Unit) -
Dispatch into sub-scopes —,
touch { … },mouse { … },key { … },rotary { … },trackpad { … }(MultiModalInjectionScope.kt:51-90). All sub-scopes share the same injection state, so a finger left "down" inindirectPointer(...)is still down whentouchruns next.mouse -
Pick this entry point when a single test step combines modalities — e.g. hover-while-shift-held — instead of stitching together two separatecalls.
perform.*Input
-
打开多模态作用域——(Actions.kt:582-594)。
performMultiModalInput(block: MultiModalInjectionScope.() -> Unit) -
分发到子作用域——、
touch { … }、mouse { … }、key { … }、rotary { … }、trackpad { … }(MultiModalInjectionScope.kt:51-90)。所有子作用域共享同一注入状态,因此如果indirectPointer(...)中有手指仍处于“按下”状态,那么随后执行touch时它依然处于按下状态。mouse -
选择此入口点。 当单个测试步骤需要组合多种模态时,例如在按住 Shift 的同时进行 hover,应使用该入口点,而不是拼接两个独立的调用。
perform.*Input
Patterns
模式
Pattern: Right-click menu
模式:右键菜单
kotlin
// RIGHT
rule.onNodeWithTag(RowTag).performMouseInput {
rightClick(center)
}
rule.onNodeWithText("Delete").assertIsDisplayed()rightClickclick(position, MouseButton.Secondary)kotlin
// RIGHT
rule.onNodeWithTag(RowTag).performMouseInput {
rightClick(center)
}
rule.onNodeWithText("Delete").assertIsDisplayed()rightClickclick(position, MouseButton.Secondary)Pattern: Hover-driven tooltip
模式:由 hover 驱动的 tooltip
From :
CombinedClickableTest.kt:3415-3422kotlin
rule.onNodeWithTag("myClickable").performMouseInput { enter(center) }
rule.runOnIdle {
assertThat(interactions).hasSize(1)
assertThat(interactions.first()).isInstanceOf(HoverInteraction.Enter::class.java)
}
rule.onNodeWithTag("myClickable").performMouseInput { exit(Offset(-1f, -1f)) }enter(position)exit(position)Offset(-1f, -1f)exit来自 :
CombinedClickableTest.kt:3415-3422kotlin
rule.onNodeWithTag("myClickable").performMouseInput { enter(center) }
rule.runOnIdle {
assertThat(interactions).hasSize(1)
assertThat(interactions.first()).isInstanceOf(HoverInteraction.Enter::class.java)
}
rule.onNodeWithTag("myClickable").performMouseInput { exit(Offset(-1f, -1f)) }enter(position)exit(position)exitOffset(-1f, -1f)Pattern: Ctrl+S shortcut — verbose vs idiomatic
模式:Ctrl+S 快捷键——冗长写法与惯用写法
kotlin
// WRONG
rule.onNodeWithTag(EditorTag).performKeyInput {
keyDown(Key.CtrlLeft)
pressKey(Key.S)
keyUp(Key.CtrlLeft)
}
// WRONG because: a thrown assertion or early-return inside the block leaks Key.CtrlLeft
// in the "down" state, polluting subsequent tests. The release is not in a finally.kotlin
// RIGHT
rule.onNodeWithTag(EditorTag).performKeyInput {
withKeyDown(Key.CtrlLeft) {
pressKey(Key.S)
}
}withKeyDownfinallywithKeysDown(listOf(Key.CtrlLeft, Key.ShiftLeft)) { pressKey(Key.S) }kotlin
// WRONG
rule.onNodeWithTag(EditorTag).performKeyInput {
keyDown(Key.CtrlLeft)
pressKey(Key.S)
keyUp(Key.CtrlLeft)
}
// WRONG because: a thrown assertion or early-return inside the block leaks Key.CtrlLeft
// in the "down" state, polluting subsequent tests. The release is not in a finally.kotlin
// RIGHT
rule.onNodeWithTag(EditorTag).performKeyInput {
withKeyDown(Key.CtrlLeft) {
pressKey(Key.S)
}
}withKeyDownfinallywithKeysDown(listOf(Key.CtrlLeft, Key.ShiftLeft)) { pressKey(Key.S) }Pattern: Repeat-key autorepeat
模式:按键自动重复
kotlin
rule.onNodeWithTag(InputTag).performKeyInput {
keyDown(Key.DirectionDown)
advanceEventTime(800) // 500 ms initial delay + 6 repeats at 50 ms
keyUp(Key.DirectionDown)
}advanceEventTimerule.mainClock.advanceTimeBy(…)kotlin
rule.onNodeWithTag(InputTag).performKeyInput {
keyDown(Key.DirectionDown)
advanceEventTime(800) // 500 ms initial delay + 6 repeats at 50 ms
keyUp(Key.DirectionDown)
}advanceEventTimerule.mainClock.advanceTimeBy(…)Pattern: Drag-and-drop with mouse
模式:使用鼠标进行拖放
kotlin
rule.onNodeWithTag(SourceTag).performMouseInput {
dragAndDrop(
start = center,
end = Offset(center.x + 200f, center.y),
durationMillis = 250,
)
}dragAndDropstartendMouseButton.Primarybutton = MouseButton.Tertiarykotlin
rule.onNodeWithTag(SourceTag).performMouseInput {
dragAndDrop(
start = center,
end = Offset(center.x + 200f, center.y),
durationMillis = 250,
)
}dragAndDropstartendMouseButton.Primarybutton = MouseButton.TertiaryPattern: Smooth scroll
模式:平滑滚动
kotlin
rule.onNodeWithTag(ScrollAreaTag).performMouseInput {
smoothScroll(
scrollAmount = -10f, // negative scrollAmount = scroll back; new content appears at the top (MouseInjectionScope.kt:537-542)
durationMillis = 200,
scrollWheel = ScrollWheel.Vertical,
)
}Positive reveals content from the bottom of a vertical column or from the end of a horizontal row (MouseInjectionScope.kt:537-542). For a single-tick wheel event, drop to .
scrollAmountscroll(delta, scrollWheel)kotlin
rule.onNodeWithTag(ScrollAreaTag).performMouseInput {
smoothScroll(
scrollAmount = -10f, // negative scrollAmount = scroll back; new content appears at the top (MouseInjectionScope.kt:537-542)
durationMillis = 200,
scrollWheel = ScrollWheel.Vertical,
)
}正的 会显示垂直列底部或水平行末尾的内容(MouseInjectionScope.kt:537-542)。如果需要仅发送一次滚轮刻度事件,可下沉到 。
scrollAmountscroll(delta, scrollWheel)Pattern: Multi-modal — hover then click while Shift held
模式:多模态——悬停后在按住 Shift 的同时点击
MultiModalInjectionScopemouse { }key { }touch { }key { withKeyDown(...) { } }performMultiModalInputmouse { }withKeyDownKeyInjectionScopemouse { }kotlin
rule.onNodeWithTag(NodeTag).performMultiModalInput {
mouse { enter(center) }
key { keyDown(Key.ShiftLeft) }
mouse { click() } // dispatched with Shift still held
key { keyUp(Key.ShiftLeft) }
}A single keeps every modality in one batched flush; the modifier-key state, pointer position, and pressed buttons are shared across sub-scopes (MultiModalInjectionScope.kt). Use it when interleaving matters; otherwise two separate / calls are clearer.
performMultiModalInputperformMouseInputperformKeyInputMultiModalInjectionScopemouse { }key { }touch { }key { withKeyDown(...) { } }performMultiModalInputmouse { }withKeyDownKeyInjectionScopemouse { }kotlin
rule.onNodeWithTag(NodeTag).performMultiModalInput {
mouse { enter(center) }
key { keyDown(Key.ShiftLeft) }
mouse { click() } // dispatched with Shift still held
key { keyUp(Key.ShiftLeft) }
}单次 会将所有模态保持在一次批量提交中;修饰键状态、指针位置和已按下按钮会在各子作用域之间共享(MultiModalInjectionScope.kt)。当各模态确实需要交错时使用它;否则,分成两个独立的 / 调用会更清晰。
performMultiModalInputperformMouseInputperformKeyInputPattern: Direct KeyEvent injection for precise control
模式:直接注入 KeyEvent 以实现精确控制
kotlin
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.test.performKeyPress
val event = KeyEvent(NativeKeyEvent(NativeKeyEvent.ACTION_DOWN, NativeKeyEvent.KEYCODE_TAB))
rule.onRoot().performKeyPress(event)performKeyPressKeyInputHelpers.kt:27KeyEventkotlin
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.test.performKeyPress
val event = KeyEvent(NativeKeyEvent(NativeKeyEvent.ACTION_DOWN, NativeKeyEvent.KEYCODE_TAB))
rule.onRoot().performKeyPress(event)performKeyPressKeyEventMandatory rules
强制规则
- MUST wrap modifier-key shortcuts in /
withKeyDownso the auto-releasewithKeysDowncleans up after a thrown assertion. Manualfinally/keyDownpairs leak modifier state across tests.keyUp - MUST use (the
advanceEventTimeclock) — NOTInjectionScope— when expecting key autorepeat events. Repeats are produced by the input dispatcher's event-time stream (KeyInjectionScope.kt:43-50).MainTestClock.advanceTimeBy - MUST keep coordinates node-local using ,
center,topLeft,bottomRight. Hardcoded screen coordinates make the test device-shaped — seepercentOffset(...).../injecting-touch-gestures/SKILL.md - MUST funnel post-action assertions through (skydoves hot take #5).
rule.runOnIdle { … } - MUST NOT use to test a finger tap on Android device tests —
performMouseInputresolves to a touch tap on Android and a mouse click on desktop, automatically.performClick() - MUST NOT use to wait between key or mouse events. Use
Thread.sleepinside the block (event-time delay) oradvanceEventTimeoutside it (frame clock delay).mainClock.advanceTimeBy - PREFERRED: select only when modalities truly interleave; otherwise separate
performMultiModalInputandperformMouseInputcalls read better.performKeyInput
- 必须将修饰键快捷键包裹在 /
withKeyDown中,使自动释放逻辑能够在断言抛出后通过withKeysDown完成清理。手动配对finally/keyDown会让修饰键状态泄漏到后续测试中。keyUp - 必须使用 (
advanceEventTime时钟),而不是InjectionScope,以期望生成按键自动重复事件。重复事件由 input dispatcher 的事件时间流生成(KeyInjectionScope.kt:43-50)。MainTestClock.advanceTimeBy - 必须使用 、
center、topLeft、bottomRight等方式保持坐标为节点本地坐标。硬编码屏幕坐标会使测试受设备形状影响——参见percentOffset(...)。../injecting-touch-gestures/SKILL.md - 必须将操作后的断言放入 中执行(skydoves 热辣观点 #5)。
rule.runOnIdle { … } - 不得在 Android 设备测试中使用 测试手指点按——
performMouseInput会在 Android 上解析为触摸点按,在桌面端解析为鼠标点击,并且会自动完成选择。performClick() - 不得使用 等待按键或鼠标事件。在块内部使用
Thread.sleep(事件时间延迟),或在块外部使用advanceEventTime(帧时钟延迟)。mainClock.advanceTimeBy - **推荐:**仅当各模态确实需要交错时选择 ;否则,分开的
performMultiModalInput和performMouseInput调用更易阅读。performKeyInput
Verification
验证
- Every modifier-key combo uses /
withKeyDownrather than rawwithKeysDown/keyDownpairs.keyUp - No between or inside
Thread.sleep/performMouseInputblocks.performKeyInput - No hardcoded screen coordinates — every is derived from
Offset(...),center,top*,bottom*, or relative deltas.percentOffset(...) - Tests asserting key autorepeat behaviour use , not
advanceEventTime.mainClock.advanceTimeBy - Assertions following an action run inside .
rule.runOnIdle { … } - (or the equivalent host / desktop task) passes for the test under change.
./gradlew :app:connectedDebugAndroidTest
- 每个修饰键组合都使用 /
withKeyDown,而不是原始的withKeysDown/keyDown配对。keyUp - 在 /
performMouseInput块内部或块之间都没有使用performKeyInput。Thread.sleep - 没有硬编码屏幕坐标——每个 都派生自
Offset(...)、center、top*、bottom*或相对位移。percentOffset(...) - 断言按键自动重复行为时使用 ,而不是
advanceEventTime。mainClock.advanceTimeBy - 操作后的断言在 中运行。
rule.runOnIdle { … } - (或等效的宿主/桌面端任务)能够通过本次修改涉及的测试。
./gradlew :app:connectedDebugAndroidTest
References
参考资料
- Compose testing overview: https://developer.android.com/develop/ui/compose/testing
- Compose Multiplatform testing: https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-test.html
- Compose testing cheat sheet: https://developer.android.com/develop/ui/compose/testing-cheatsheet
- —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Actions.kt(Actions.kt:448),performMouseInput(Actions.kt:532),performKeyInput(Actions.kt:582),performMultiModalInput,performTrackpadInput.performRotaryScrollInput - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MouseInjectionScope.kt,press,release,moveTo,moveBy,enter,exit,scroll, plus extensionscancel,click,rightClick,doubleClick,tripleClick,longClick,animateMoveTo,animateMoveBy,animateMoveAlong,dragAndDrop.smoothScroll - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/KeyInjectionScope.kt,keyDown,keyUp, modifier-state vals,isKeyDown,pressKey,withKeyDown,withKeysDown,withKeyToggled, repeat-key contract.withKeysToggled - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/KeyInputHelpers.kt(KeyInputHelpers.kt:27).performKeyPress(KeyEvent): Boolean - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Mouse.kt/MouseButton.Primary/Secondary,Tertiary/ScrollWheel.Horizontal.Vertical - —
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MultiModalInjectionScope.kt,touch,mouse,key,rotary,trackpad.indirectPointer - —
compose/foundation/foundation/src/androidDeviceTest/.../CombinedClickableTest.kt,performMouseInput { enter(center) }(CombinedClickableTest.kt:3415-3422).performMouseInput { exit(Offset(-1f, -1f)) } - skydoves — compose-performance-skills: https://github.com/skydoves/compose-performance-skills
- Compose 测试概览:https://developer.android.com/develop/ui/compose/testing
- Compose Multiplatform 测试:https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-test.html
- Compose 测试速查表:https://developer.android.com/develop/ui/compose/testing-cheatsheet
- ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Actions.kt(Actions.kt:448)、performMouseInput(Actions.kt:532)、performKeyInput(Actions.kt:582)、performMultiModalInput、performTrackpadInput。performRotaryScrollInput - ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MouseInjectionScope.kt、press、release、moveTo、moveBy、enter、exit、scroll,以及扩展函数cancel、click、rightClick、doubleClick、tripleClick、longClick、animateMoveTo、animateMoveBy、animateMoveAlong、dragAndDrop。smoothScroll - ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/KeyInjectionScope.kt、keyDown、keyUp、修饰键状态属性、isKeyDown、pressKey、withKeyDown、withKeysDown、withKeyToggled、按键重复行为约定。withKeysToggled - ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/KeyInputHelpers.kt(KeyInputHelpers.kt:27)。performKeyPress(KeyEvent): Boolean - ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/Mouse.kt/MouseButton.Primary/Secondary,Tertiary/ScrollWheel.Horizontal。Vertical - ——
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MultiModalInjectionScope.kt、touch、mouse、key、rotary、trackpad。indirectPointer - ——
compose/foundation/foundation/src/androidDeviceTest/.../CombinedClickableTest.kt、performMouseInput { enter(center) }(CombinedClickableTest.kt:3415-3422)。performMouseInput { exit(Offset(-1f, -1f)) } - skydoves——compose-performance-skills:https://github.com/skydoves/compose-performance-skills