lecture 6 of 150 completed

One test, many datasets

Ten copies of the same test with different values is a maintenance problem. Loop over the data instead, and keep the failures readable.

What you'll learn

  • How to turn repeated tests into data plus one test body
  • Why each case must fail on its own
  • When a unit test is the better tool

A card validation suite can end up with eleven copies of the same test. Same steps every time, only the card number changes. When the error message is reworded, that is eleven blocks to edit, and one will be missed.

The fix is to describe the cases as data, and let one test body handle all of them.

Start with the cases in a plain array:

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 →