controlling-the-test-clock
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseControlling the Test Clock — Frames, Time, and the Recomposer
控制测试时钟——帧、时间与 Recomposer
MainTestClockLaunchedEffectautoAdvanceMainTestClockLaunchedEffectautoAdvanceWhen to use this skill
何时使用此 skill
- The developer asks what actually does, why it rounds up, or why the animation seems off by one frame.
mainClock.advanceTimeBy(...) - The developer is migrating from (v1) to
androidx.compose.ui.test.junit4.createComposeRule(v2) and tests now require an explicitandroidx.compose.ui.test.junit4.v2.createComposeRuleormainClock.runCurrent().advanceTimeBy(0) - The developer mentions ,
MainTestClock,TestCoroutineScheduler,TestMonotonicFrameClock,ComposeTimeoutException, or "test clock vs wall clock".advanceTimeUntil - The developer is writing a test that needs a particular frame count and is unsure whether produces zero, one, or many frames.
advanceTimeBy(5) - The developer asks why the animation's is still
playTimeafter one frame.0
- 开发者询问 实际做了什么、为什么会向上取整,或者为什么动画看起来差了一帧。
mainClock.advanceTimeBy(...) - 开发者正在从 (v1)迁移到
androidx.compose.ui.test.junit4.createComposeRule(v2),而测试现在需要显式调用androidx.compose.ui.test.junit4.v2.createComposeRule或mainClock.runCurrent()。advanceTimeBy(0) - 开发者提及 、
MainTestClock、TestCoroutineScheduler、TestMonotonicFrameClock、ComposeTimeoutException或 test clock vs wall clock。advanceTimeUntil - 开发者编写的测试需要特定的帧数,但不确定 会产生零帧、一帧还是多帧。
advanceTimeBy(5) - 开发者询问为什么动画经过一帧后,其 仍然是
playTime。0
When NOT to use this skill
何时不应使用此 skill
- The goal is a deterministic animation test (the recipe). Use
autoAdvance = false.../testing-animations-deterministically/SKILL.md - The goal is to wait on s, async work, or "the UI is settled". Use
IdlingResource.../synchronizing-with-idle/SKILL.md - The goal is the higher-level test structure (rule wiring, , JUnit lifecycle). Use
setContent.../../patterns/structuring-a-compose-test/SKILL.md - The goal is choosing between and
createComposeRule. UserunComposeUiTest.../../setup/choosing-test-rule-vs-runtest/SKILL.md
- 目标是编写确定性的动画测试(配方)。请使用
autoAdvance = false。../testing-animations-deterministically/SKILL.md - 目标是等待 、异步工作或“UI 已稳定”。请使用
IdlingResource。../synchronizing-with-idle/SKILL.md - 目标是处理更高层的测试结构(rule 配置、、JUnit 生命周期)。请使用
setContent。../../patterns/structuring-a-compose-test/SKILL.md - 目标是在 与
createComposeRule之间做选择。请使用runComposeUiTest。../../setup/choosing-test-rule-vs-runtest/SKILL.md
Prerequisites
前置条件
- and
androidx.compose.ui:ui-test(or the JUnit-lessandroidx.compose.ui:ui-test-junit4) on the test source set.runComposeUiTest - A from
ComposeContentTestRuleor acreateComposeRule()receiver fromComposeUiTest.runComposeUiTest { … } - PREFERRED: the v2 entry points (,
androidx.compose.ui.test.junit4.v2.createComposeRule). The v1 forms areandroidx.compose.ui.test.v2.runComposeUiTest(skydoves hot take #6).@Deprecated(level = WARNING)
- 测试 source set 中包含 和
androidx.compose.ui:ui-test(或不含 JUnit 的androidx.compose.ui:ui-test-junit4)。runComposeUiTest - 拥有来自 的
createComposeRule(),或来自ComposeContentTestRule的runComposeUiTest { … }receiver。ComposeUiTest - **推荐:**使用 v2 入口点(、
androidx.compose.ui.test.junit4.v2.createComposeRule)。v1 形式已被弃用,级别为androidx.compose.ui.test.v2.runComposeUiTest(skydoves 的个人观点 #6)。WARNING
The mental model
心智模型
MainTestClockMonotonicFrameClockkotlinx.coroutines.test.TestCoroutineSchedulerTestMonotonicFrameClockwithFrameNanosdelay(frameDelayMillis)TestMonotonicFrameClock.jvmAndAndroid.kt:105-117delayonPerformTraversalsMainTestClock.advanceTimeBy(ms)
│
▼ AbstractMainTestClock.advanceScheduler
TestCoroutineScheduler.advanceTimeBy(ms) → runCurrent()
│
▼ delay(frameDelayMillis) inside TestMonotonicFrameClock fires
performFrame() ── awaiters (withFrameNanos) resume FIRST
│ ── then onPerformTraversals → recomposition → measure/layout
▼
Recomposer applies snapshot writesThis is why is enough to freeze the entire UI: nothing else ticks the scheduler unless an explicit call is made ( KDoc).
autoAdvance = falsemainClock.advance*MainTestClock.kt:43-48MainTestClockMonotonicFrameClockkotlinx.coroutines.test.TestCoroutineSchedulerTestMonotonicFrameClockwithFrameNanosdelay(frameDelayMillis)TestMonotonicFrameClock.jvmAndAndroid.kt:105-117delayonPerformTraversalsMainTestClock.advanceTimeBy(ms)
│
▼ AbstractMainTestClock.advanceScheduler
TestCoroutineScheduler.advanceTimeBy(ms) → runCurrent()
│
▼ delay(frameDelayMillis) inside TestMonotonicFrameClock fires
performFrame() ── awaiters (withFrameNanos) resume FIRST
│ ── then onPerformTraversals → recomposition → measure/layout
▼
Recomposer applies snapshot writes这就是为什么仅设置 就足以冻结整个 UI:除非显式调用 ,否则不会有其他机制推动 scheduler 前进( KDoc)。
autoAdvance = falsemainClock.advance*MainTestClock.kt:43-48The MainTestClock surface
MainTestClock API
Every entry comes from .
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MainTestClock.kt| Member | Behavior |
|---|---|
| Test clock time in milliseconds. NOT wall clock. Reads |
| The scheduler the recomposer and clock share. Useful for |
| Default |
| Advances by exactly one frame (16 ms on Android/Desktop). Implemented as |
| Rounds up to the nearest multiple of frame duration unless |
| Advances frame-by-frame until |
runCurrent()AbstractMainTestClockAbstractMainTestClock.kt:96-98每个入口都来自 。
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MainTestClock.kt| 成员 | 行为 |
|---|---|
| 以毫秒为单位的测试时钟时间。不是实际时间。读取 |
| Recomposer 与时钟共享的 scheduler。可用于从外部调用 |
| 默认为 |
| 精确推进一帧(Android/Desktop 上为 16 ms)。通过 |
| 除非设置 |
| 逐帧推进,直到 |
runCurrent()AbstractMainTestClockAbstractMainTestClock.kt:96-98The frame model
帧模型
- Frame duration: ns = 16 ms (
DefaultFrameDelay = 16_000_000L).TestMonotonicFrameClock.jvmAndAndroid.kt:33 - Per-frame order inside :
performFrame- All awaiters resume with the new frame time. Animations live here.
withFrameNanos - runs — composition + measure + layout.
onPerformTraversals - Resumptions queued by the awaiters are dispatched.
- All
Quoted from :
MainTestClock.kt:49-60If there is both a pending recomposition and an animation awaiting a frame time, ticking this clock will first send the new frame time to the animation, and then perform recomposition. … Because animations receive their frame time before recomposition, an animation will not get its start time in the first frame after kicking it off by toggling a state variable.
That last sentence is the reason every animation test does an extra immediately after to "kick off" the animation: the toggle frame schedules the animation; the next frame initializes its play time to (skydoves hot take #3).
advanceTimeByFrame()setContent0- 帧时长:ns,即 16 ms(
DefaultFrameDelay = 16_000_000L)。TestMonotonicFrameClock.jvmAndAndroid.kt:33 - 内的每帧顺序:
performFrame- 所有 等待者使用新的帧时间恢复执行。动画位于此处。
withFrameNanos - 执行 ——composition、measure 和 layout。
onPerformTraversals - 调度由等待者触发的恢复执行。
- 所有
引用自 :
MainTestClock.kt:49-60如果同时存在待处理的重组和等待帧时间的动画,tick 此时钟会_首先_将新的帧时间发送给动画,_然后_执行重组。……由于动画在重组_之前_收到帧时间,因此通过切换状态变量启动动画后的第一帧中,动画不会获得其开始时间。
最后一句正是每个动画测试都要在 后立即额外调用一次 来“启动”动画的原因:切换状态的帧只会调度动画;下一帧会将动画的 play time 初始化为 (skydoves 的个人观点 #3)。
setContentadvanceTimeByFrame()0Workflow
工作流
1. Read currentTime
only as a witness, never as a synchronization mechanism
currentTime1. 仅将 currentTime
作为校验依据读取,绝不将其用作同步机制
currentTimekotlin
// RIGHT — assert the clock advanced as much as the test asked
val before = rule.mainClock.currentTime
rule.mainClock.advanceTimeBy(durationMillis = 320)
assertEquals(320, rule.mainClock.currentTime - before)kotlin
// WRONG
while (rule.mainClock.currentTime < target) { /* spin */ }
// WRONG because: nothing in this loop drives the scheduler. The loop runs forever.kotlin
// RIGHT — assert the clock advanced as much as the test asked
val before = rule.mainClock.currentTime
rule.mainClock.advanceTimeBy(durationMillis = 320)
assertEquals(320, rule.mainClock.currentTime - before)kotlin
// WRONG
while (rule.mainClock.currentTime < target) { /* spin */ }
// WRONG because: nothing in this loop drives the scheduler. The loop runs forever.2. Choose the right advance method
2. 选择正确的推进方法
| Goal | Call |
|---|---|
| "Run exactly one frame." | |
| "Run N frames." | |
| "Run a known animation duration." | |
| "Step time without producing a new frame." | |
| "Wait until a Compose state condition becomes true." | |
| 目标 | 调用 |
|---|---|
| “恰好运行一帧。” | |
| “运行 N 帧。” | |
| “运行一段已知时长的动画。” | |
| “推进时间但不产生新帧。” | |
| “等待某个 Compose 状态条件变为 true。” | |
3. After mutating state under v2, run pending tasks before asserting
3. 在 v2 中修改状态后,先运行待处理任务再断言
The v2 uses a for composition; tasks are queued, not executed immediately. If , neither nor a node query will drain those tasks. The fix is or :
createComposeRuleStandardTestDispatcherautoAdvance = falsewaitForIdlemainClock.runCurrent()mainClock.advanceTimeBy(0)kotlin
rule.mainClock.autoAdvance = false
rule.runOnUiThread { uiState = newValue }
// Under v2, the snapshot write is queued. Drain it before asserting.
rule.mainClock.advanceTimeByFrame()
rule.onNodeWithTag("status").assertTextEquals("Updated")AbstractMainTestClock.advanceTimeUntilscheduler.runCurrent()isStandardTestDispatcherSupportEnabledAbstractMainTestClock.kt:59-61v2 的 使用 执行 composition;任务会被排队,而不是立即执行。如果 ,那么 和节点查询都不会清空这些任务。解决方法是调用 或 :
createComposeRuleStandardTestDispatcherautoAdvance = falsewaitForIdlemainClock.runCurrent()mainClock.advanceTimeBy(0)kotlin
rule.mainClock.autoAdvance = false
rule.runOnUiThread { uiState = newValue }
// Under v2, the snapshot write is queued. Drain it before asserting.
rule.mainClock.advanceTimeByFrame()
rule.onNodeWithTag("status").assertTextEquals("Updated")当 为 true 时, 已经首先调用 ()。
isStandardTestDispatcherSupportEnabledAbstractMainTestClock.advanceTimeUntilscheduler.runCurrent()AbstractMainTestClock.kt:59-614. Treat ComposeTimeoutException
as a verdict on the condition, not on the clock
ComposeTimeoutException4. 将 ComposeTimeoutException
视为对条件而非时钟的判定
ComposeTimeoutExceptionadvanceTimeUntilComposeTimeoutException("Condition still not satisfied after $timeoutMillis ms")timeoutMilliscondition()trueAbstractMainTestClock.kt:65-68LaunchedEffect当测试时钟推进超过 ,但 仍未返回 true 时, 会抛出 ()。该异常意味着仅靠时钟驱动的工作永远无法满足条件——通常是因为缺少 snapshot write、 未能启动,或在错误的线程上读取了状态。
timeoutMilliscondition()advanceTimeUntilComposeTimeoutException("Condition still not satisfied after $timeoutMillis ms")AbstractMainTestClock.kt:65-68LaunchedEffectPatterns
模式
Pattern: rounding up
模式:向上取整
kotlin
// WRONG
rule.mainClock.advanceTimeBy(milliseconds = 5)
// expectation: "1 frame ran"
// WRONG because: the framework rounds 5 ms UP to the next 16 ms multiple — i.e. 16 ms.
// One frame did run, but the developer is reading the API as if it could advance by 5 ms.
// Use ignoreFrameDuration = true if sub-frame stepping is genuinely required.kotlin
// RIGHT
rule.mainClock.advanceTimeByFrame() // exactly 16 ms, exactly one frame
// or
rule.mainClock.advanceTimeBy(milliseconds = 5, ignoreFrameDuration = true) // 5 ms, 0 frameskotlin
// WRONG
rule.mainClock.advanceTimeBy(milliseconds = 5)
// expectation: "1 frame ran"
// WRONG because: the framework rounds 5 ms UP to the next 16 ms multiple — i.e. 16 ms.
// One frame did run, but the developer is reading the API as if it could advance by 5 ms.
// Use ignoreFrameDuration = true if sub-frame stepping is genuinely required.kotlin
// RIGHT
rule.mainClock.advanceTimeByFrame() // exactly 16 ms, exactly one frame
// or
rule.mainClock.advanceTimeBy(milliseconds = 5, ignoreFrameDuration = true) // 5 ms, 0 framesPattern: the "kick-off" frame for animations
模式:动画的“启动帧”
kotlin
// WRONG
rule.mainClock.autoAdvance = false
rule.setContent { Crossfade(showFirst) { /* … */ } }
rule.mainClock.advanceTimeBy(300) // expect animation finished
rule.onNodeWithText("Second").assertExists()
// WRONG because: the toggle frame only schedules the animation; the animation's playTime is 0
// going into the next frame. The first 16 ms of the 300 are eaten by setup.kotlin
// RIGHT — see CrossfadeTest.kt:70-93
rule.mainClock.autoAdvance = false
rule.setContent { Crossfade(showFirst) { /* … */ } }
rule.mainClock.advanceTimeByFrame() // kick off
rule.mainClock.advanceTimeBy(durationMillis = 300) // step
rule.onNodeWithText("Second").assertExists()kotlin
// WRONG
rule.mainClock.autoAdvance = false
rule.setContent { Crossfade(showFirst) { /* … */ } }
rule.mainClock.advanceTimeBy(300) // expect animation finished
rule.onNodeWithText("Second").assertExists()
// WRONG because: the toggle frame only schedules the animation; the animation's playTime is 0
// going into the next frame. The first 16 ms of the 300 are eaten by setup.kotlin
// RIGHT — see CrossfadeTest.kt:70-93
rule.mainClock.autoAdvance = false
rule.setContent { Crossfade(showFirst) { /* … */ } }
rule.mainClock.advanceTimeByFrame() // kick off
rule.mainClock.advanceTimeBy(durationMillis = 300) // step
rule.onNodeWithText("Second").assertExists()Pattern: v1 → v2 migration leaves a state read stale
模式:v1 → v2 迁移后状态读取仍然陈旧
kotlin
// WRONG (v2)
val rule = androidx.compose.ui.test.junit4.v2.createComposeRule()
@Test fun foo() {
var counter by mutableStateOf(0)
rule.setContent { Text(counter.toString()) }
rule.runOnUiThread { counter = 1 }
rule.onNodeWithText("1").assertExists()
// WRONG because: with StandardTestDispatcher, the snapshot apply is queued.
// No frame has been produced. The composition still reads `0`.
}kotlin
// RIGHT (v2)
@Test fun foo() {
var counter by mutableStateOf(0)
rule.setContent { Text(counter.toString()) }
rule.runOnUiThread { counter = 1 }
rule.mainClock.advanceTimeByFrame()
rule.onNodeWithText("1").assertExists()
}kotlin
// WRONG (v2)
val rule = androidx.compose.ui.test.junit4.v2.createComposeRule()
@Test fun foo() {
var counter by mutableStateOf(0)
rule.setContent { Text(counter.toString()) }
rule.runOnUiThread { counter = 1 }
rule.onNodeWithText("1").assertExists()
// WRONG because: with StandardTestDispatcher, the snapshot apply is queued.
// No frame has been produced. The composition still reads `0`.
}kotlin
// RIGHT (v2)
@Test fun foo() {
var counter by mutableStateOf(0)
rule.setContent { Text(counter.toString()) }
rule.runOnUiThread { counter = 1 }
rule.mainClock.advanceTimeByFrame()
rule.onNodeWithText("1").assertExists()
}Pattern: advanceTimeUntil
saves wall time
advanceTimeUntil模式:advanceTimeUntil
节省实际耗时
advanceTimeUntilkotlin
// LESS PREFERRED — wall clock
rule.waitUntil(timeoutMillis = 5_000) { state.value == Phase.Done }kotlin
// PREFERRED — test clock; framework iterates frame-by-frame and the timeout is in
// test clock time (no real wall-clock burn between iterations).
rule.mainClock.advanceTimeUntil(timeoutMillis = 5_000) { state.value == Phase.Done }Both variants advance the test clock when : calls AND per iteration (); only advances the test clock by frames (). The difference is the timeout source — wall vs test — and the absence of overhead in the test-clock variant.
autoAdvance == truewaitUntilmainClock.advanceTimeByFrame()Thread.sleep(10)ComposeUiTest.android.kt:899-902advanceTimeUntilAbstractMainTestClock.kt:54-72Thread.sleepkotlin
// LESS PREFERRED — wall clock
rule.waitUntil(timeoutMillis = 5_000) { state.value == Phase.Done }kotlin
// PREFERRED — test clock; framework iterates frame-by-frame and the timeout is in
// test clock time (no real wall-clock burn between iterations).
rule.mainClock.advanceTimeUntil(timeoutMillis = 5_000) { state.value == Phase.Done }当 时,两个变体都会推进测试时钟: 每次迭代都会调用 并执行 (); 只会按帧推进测试时钟()。二者的区别在于超时时间来源——实际时间与测试时间——以及测试时钟变体不存在 开销。
autoAdvance == truewaitUntilmainClock.advanceTimeByFrame()Thread.sleep(10)ComposeUiTest.android.kt:899-902advanceTimeUntilAbstractMainTestClock.kt:54-72Thread.sleepMandatory rules
强制规则
- MUST treat as test clock time only. Comparing it to
MainTestClock.currentTimeis meaningless.System.currentTimeMillis() - MUST call (not
advanceTimeByFrame()) when the intent is "exactly one frame." It documents intent and avoids reasoning about rounding.advanceTimeBy(16) - MUST know that rounds up to the next multiple of
advanceTimeBy(milliseconds = N)(16 ms on Android/Desktop). PassframeDelayMillisto suppress rounding (ignoreFrameDuration = true).AbstractMainTestClock.kt:44-52 - MUST call (or
advanceTimeByFrame()/advanceTimeBy(0)) after toggling state under v2 (runCurrent()) before reading the resulting UI state. v1'sStandardTestDispatcherdispatches eagerly and does not need this; v2 does (skydoves hot take #6).UnconfinedTestDispatcher - MUST NOT use for conditions outside Compose's snapshot system (e.g. a
advanceTimeUntil, anJob.isCompletedcallback). Those conditions will never become true by ticking the test clock —OkHttp(wall clock) or anwaitUntilis the right tool. SeeIdlingResource.../synchronizing-with-idle/SKILL.md - MUST NOT confuse with
MainTestClock. They are different types.MonotonicFrameClockexposes the scheduler that drives theMainTestClockthe recomposer uses.TestMonotonicFrameClock - PREFERRED: the v2 entry points so the dispatcher matches semantics. The v1
kotlinx.coroutines.test.runTest/createComposeRuleforms are deprecatedrunComposeUiTest.WARNING - PREFERRED: over
advanceTimeUntilwhenever the awaited condition is observable through Compose state. Test clock is faster and deterministic; wall clock sleeps 10 ms per iteration.waitUntil
- 必须将 仅视为测试时钟时间。将其与
MainTestClock.currentTime比较毫无意义。System.currentTimeMillis() - 必须在意图为“恰好一帧”时调用 (而不是
advanceTimeByFrame())。这样可以明确表达意图,并避免考虑取整规则。advanceTimeBy(16) - 必须了解 会向上取整到下一个
advanceTimeBy(milliseconds = N)倍数(Android/Desktop 上为 16 ms)。传入frameDelayMillis可禁止取整(ignoreFrameDuration = true)。AbstractMainTestClock.kt:44-52 - 必须在 v2()下切换状态后,调用
StandardTestDispatcher(或advanceTimeByFrame()/advanceTimeBy(0)),然后再读取生成的 UI 状态。v1 的runCurrent()会立即调度,因此不需要这样做;v2 需要(skydoves 的个人观点 #6)。UnconfinedTestDispatcher - 不得将 用于 Compose snapshot 系统之外的条件(例如
advanceTimeUntil、Job.isCompletedcallback)。仅通过 tick 测试时钟,这些条件永远不会变为 true——应使用OkHttp(实际时间)或waitUntil。请参阅IdlingResource。../synchronizing-with-idle/SKILL.md - 不得混淆 与
MainTestClock。它们是不同类型。MonotonicFrameClock公开 scheduler,由该 scheduler 驱动 Recomposer 使用的MainTestClock。TestMonotonicFrameClock - **推荐:**使用 v2 入口点,使 dispatcher 与 的语义保持一致。v1 的
kotlinx.coroutines.test.runTest/createComposeRule形式已被弃用,级别为runComposeUiTest。WARNING - **推荐:**只要等待条件能够通过 Compose 状态观测,就优先使用 而不是
advanceTimeUntil。测试时钟更快且具有确定性;实际时间变体每次迭代都会休眠 10 ms。waitUntil
Verification
验证
- Every call site uses for "one frame" and
advanceTimeByFrame()only when the duration is meaningful.advanceTimeBy(...) - No where
advanceTimeBy(milliseconds = X)exists without a comment explaining the intent or anX < 16flag.ignoreFrameDuration = true - After v1 → v2 migration, every state mutation followed by an assertion either calls /
mainClock.advanceTimeByFrame()/advanceTimeBy(0)or relies onrunCurrent()to drain queued tasks.runOnIdle { … } - sites read Compose state only — no
advanceTimeUntil, no external counters.Job.isCompleted - from a clock test is treated as a missing snapshot write or wrong-thread state read, not a "raise the timeout" event.
ComposeTimeoutException
- 每个调用点在需要“运行一帧”时都使用 ,仅在时长具有实际意义时使用
advanceTimeByFrame()。advanceTimeBy(...) - 不存在未附意图说明或 标志的
ignoreFrameDuration = true,其中advanceTimeBy(milliseconds = X)。X < 16 - 从 v1 迁移到 v2 后,每次状态修改后的断言之前,都会调用 /
mainClock.advanceTimeByFrame()/advanceTimeBy(0),或依赖runCurrent()清空已排队的任务。runOnIdle { … } - 的调用点只读取 Compose 状态——不读取
advanceTimeUntil或外部计数器。Job.isCompleted - 将时钟测试中的 视为缺少 snapshot write 或错误线程状态读取,而不是“应该提高超时时间”的事件。
ComposeTimeoutException
References
参考资料
- Android Developers — Compose testing: https://developer.android.com/develop/ui/compose/testing
- Android Developers — Testing animations: https://developer.android.com/develop/ui/compose/animation/testing
- Compose UI release notes: https://developer.android.com/jetpack/androidx/releases/compose-ui
- — the public interface and
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MainTestClock.kt.ComposeTimeoutException - — the rounding rule,
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/AbstractMainTestClock.kt,runCurrent.advanceScheduler - —
compose/ui/ui-test/src/jvmAndAndroidMain/kotlin/androidx/compose/ui/test/TestMonotonicFrameClock.jvmAndAndroid.kt, theDefaultFrameDelay = 16_000_000L-based frame loop.delay - — the Android actual.
compose/ui/ui-test/src/androidMain/kotlin/androidx/compose/ui/test/MainTestClockImpl.android.kt - —
compose/ui/ui-test/src/androidMain/kotlin/androidx/compose/ui/test/ComposeUiTest.android.kt's 10 ms wall-clock sleep at line 885-905.waitUntil - Sibling skill: — the full
../testing-animations-deterministically/SKILL.mdrecipe.autoAdvance = false - Sibling skill: — choosing between
../synchronizing-with-idle/SKILL.md,waitForIdle, andwaitUntil.advanceTimeUntil
- Android Developers——Compose 测试:https://developer.android.com/develop/ui/compose/testing
- Android Developers——动画测试:https://developer.android.com/develop/ui/compose/animation/testing
- Compose UI 发行说明:https://developer.android.com/jetpack/androidx/releases/compose-ui
- ——公共接口和
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/MainTestClock.kt。ComposeTimeoutException - ——取整规则、
compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/AbstractMainTestClock.kt、runCurrent。advanceScheduler - ——
compose/ui/ui-test/src/jvmAndAndroidMain/kotlin/androidx/compose/ui/test/TestMonotonicFrameClock.jvmAndAndroid.kt和基于DefaultFrameDelay = 16_000_000L的帧循环。delay - ——Android actual。
compose/ui/ui-test/src/androidMain/kotlin/androidx/compose/ui/test/MainTestClockImpl.android.kt - ——第 885-905 行中
compose/ui/ui-test/src/androidMain/kotlin/androidx/compose/ui/test/ComposeUiTest.android.kt的 10 ms 实际时间休眠。waitUntil - 同级 skill:——完整的
../testing-animations-deterministically/SKILL.md配方。autoAdvance = false - 同级 skill:——如何在
../synchronizing-with-idle/SKILL.md、waitForIdle和waitUntil之间选择。advanceTimeUntil