Testing Lottie Animations in Jetpack Compose
Article Summary
Jordi Coll Marin from Just Eat Takeaway reveals a testing challenge most Android devs overlook: how do you verify a Lottie animation actually completes when it only runs for half a second?
Testing animations in Jetpack Compose isn't straightforward, especially when they're short-lived and run only once. Jordi breaks down three distinct approaches to testing Lottie animations in Compose, each with different tradeoffs for controlling animation state during UI tests.
Key Takeaways
- MainTestClock lets you manually jump to specific frames using advanceTimeBy
- CompositionLocal with iterations prevents animation from finishing before assertion runs
- ClipSpec approach keeps progress below 1.0 so animation never leaves screen
- Default animateLottieCompositionAsState progress runs from 0 (not started) to 1 (finished)
Critical Insight
Three different testing strategies (MainTestClock, iterations control, and clipSpec manipulation) each solve the problem of verifying short-lived Lottie animations in Compose tests.