D
TestingEasy20 XP3 min read

What is the difference between pump(), pumpWidget(), and pumpAndSettle()?

TL;DR: pumpWidget() renders a widget for the first time. pump() advances the clock one frame (for animations/timers). pumpAndSettle() repeatedly calls pump() until no more frames are scheduled (all animations complete).

Full Answer

  • pumpWidget(widget): Initial render — sets up the widget tree
  • pump([duration]): Advances the clock by one frame (or specified duration). Use for step-by-step animation testing
  • pumpAndSettle([duration]): Keeps pumping until the frame queue is empty. Use after taps or navigation to let animations finish
⚠️

pumpAndSettle() will throw if animations never settle (e.g., infinite looping animations). Use pump() with explicit durations in that case.

Code Examples

dartpump vs pumpAndSettle
Output
// pumpAndSettle: waits for all frames
// pump(150ms): precise mid-animation snapshot

Common Mistakes

  • Using pumpAndSettle() when there are indefinitely repeating animations — causes a timeout
  • Forgetting to pump after tap() — the tap is queued but the UI hasn't updated yet

Interview Tip

💡

This question tests whether you've actually written widget tests. Knowing when pumpAndSettle() hangs (looping animations) shows real experience.

#pump#pumpAndSettle#widget-tester#async