Use Unique Values

The readability and usefulness of tests are enhanced when the values used to construct fixtures are mutually distinct. Within a test, unique values reinforce the differences between various assertions and help highlight when the implementation has miswired parameters or properties. Between iterations of a data-driven test, distinct values help to highlight the failing test case more clearly. The same effect applies between tests, in which case unique values also help to identify the effects of shared state.

Assertion failures generally provide good feedback on the values involved and the location in the code. However, some assertions, like assertTrue, do not display their contributing expression values. Assertions in loops ...

Get Quality Code: Software Testing Principles, Practices, and Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.