Brittle Tests - How to avoid them by thinking about your tests before you write them

Brittle Tests - How to avoid them by thinking about your tests before you write them

There is nothing more frustrating than trying to get a new feature out, and after a small refactor of just moving code around suddenly all your tests are failing (brittle tests).

The feature itself can be working perfectly - just the tests are brittle and giving false negatives.

Of course, there are times when doing refactors that you'd expect your tests to fail. But you don't want your tests to be so rigid and brittle that seemingly unrelated changes causes random tests to fail, because they were written in a way that gives no flexibility when the rest of the app changes its implementation

In this lesson I'll cover how to avoid brittle tests, how to write your tests in a way to make them maintainable, and some red flags in your tests that indicate they might be causing long term test maintenance hell.

What Are Brittle Tests?

Brittle tests are tests that break easily when you make changes to your code, even when those changes don't affect the actual behaviour or functionality being tested.

It normally comes down to heavily testing implementation details or over mocking, instead of focusing on user facing interactions and behaviour.

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.