What are flaky tests and approaches to avoid having them in your test suite

What are flaky tests and approaches to avoid having them in your test suite

The last lesson was about brittle tests that are hard to maintain and need constant attention. The other side of annoying tests that fail are when you have tests that sometimes pass, sometimes fail - even on re-runs with no changes in the code or inputs (flaky tests).

What Are Flaky Tests?

Flaky tests are tests which sometimes pass and sometimes fail. They cause you to have to retry/rerun your test suite, and end up being a huge source of annoyance and a waste of time.

They can often happen because of things like previously run tests 'leaking' something to other tests, tests rely on inputs which change (such as Math.random() or the current date/time) or because asynchronous behaviour isn't awaited correctly.

Eliminating flaky tests is as important as eliminating bugs in your production code. If you have tests that sometimes fail, software engineers working on the code will either have to waste time re-running tests, or end up merging with failing tests which always leads to accidentally merging in a failing non-flaky test by mistake.

In this lesson we will cover the types of flaky tests you often come across and how to avoid them.

Loading full lesson...

Share this lesson with your teamTweet (X) it

Invite a teammate to learn with you by sharing this lesson or dropping the link in your team chat.