Chapter 10: Tests

One kind of double deserves a warning, because it is the easiest way for an agent to write a test that tests only itself.

Mock

A test double that records how it was called, so the test can check the calls. In casual use, people say mock for any stand-in.

If the agent mocks too much, the test exercises the mocks and not your code. It stays green whatever you break, and it fails when you tidy up the internals.

Say it to your agent

“This test mocks priceCart and then only checks that it was called. Keep our code real and mock only the payment gateway. Assert on the amount it received. Then break priceCart on purpose and show me the test failing.”

The workshop

Name a word, or describe what you mean in everyday language.