Demo: hunting a flaky test
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
find the cause of a flaky test and fix it. Prepares JNR-047-LAB1.
Draft outline details
Step by step
- Run the suite ten times and note which test fails sometimes.
- Run that test alone, then in random order, to see whether it depends on order.
- Spot the cause: it uses
LocalDate.now()near midnight, or leftover data. - Inject a fixed
Clockand use unique data. - Planned mistake: add
Thread.sleepand see it still flake; replace with a deterministic clock. - Run ten times again and record the runtime.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.