lecture 5 of 150 completed

Tests that fight over the same data

Two tests using the same name will break each other. Give every test data that belongs only to it.

What you'll learn

  • Why two tests sharing data break each other
  • How to give every test data that belongs only to it
  • Why unique data beats careful cleanup

Two engineers can spend a whole afternoon on a failing build, reading the app code, checking the database, and blaming the server, when the real cause is two tests that both created a customer named "Test User".

This is one of the most confusing bugs you will meet, so let's walk through it slowly.

You have two tests. Both create a contact named "Dana Fox".

Run the first one alone: it passes. Run the second one alone: it passes. Run them together: the second one fails. It expected to find one Dana Fox and it found two.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →