Skip to content

How to design one

Make the fixture minimal, deterministic and explicit; if the test needs three users, create exactly three, not a database dump of two thousand.

A fixture that explains the test

  1. Create only what the test reads

    If the test asserts on two rows, insert two rows. A 500-row dump hides which row mattered.

  2. Use a factory, not a dump

    A factory makes the data visible in the test. A dump hides it in a file.

  3. Tear down in reverse order

    If you opened a transaction, then a file, then a socket, close the socket, the file, then the transaction.

  4. Name the fixture after the scenario

    a_user_with_expired_card, not setup2. The name is the documentation.