lecture 6 of 160 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".

Let's walk through why this is so hard to see.

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

Run the first alone: it passes. Run the second alone: it passes. Run them together: the second fails, because it expected one Dana Fox and found two.

Now it gets worse. When the team splits the suite across machines to save time, the failure moves around. Someone re-runs the build and it passes. Nobody can reproduce it.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →