No More Flaky Clock Tests
July 14, 2020
“Testing Without Mocks” Training
Jun62023I’m offering live online training for this material in four 3-hour sessions from June 6th to 15th. Register here.
To be notified about future “Testing Without Mocks” training courses, join the mailing list here (requires Google login).
For private training, contact me directly.
Every week in my Tuesday Lunch & Learn livestream, we choose a useful software development skill, define a challenge related to that skill, and solve the challenge live. This week, we’re preventing flaky clock tests.
There’s nothing more frustrating than flaky tests: tests that fail randomly. You end up having to run your test suite over and over to get a good result, even if there’s nothing wrong with your actual code. And code that involves time—that interacts with the system clock—are one of the most common cause of flaky tests.
In today’s episode, we kill flaky clock tests dead. If you use these techniques, you’ll never have another flaky clock test.
To follow along, download the code from GitHub and check out the 2020-07-14
tag. To see the final result, check out the 2020-07-14-end
tag or view it on GitHub.
Visit the Lunch & Learn archive for more.