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:

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 →