Making Test Inputs Explain Themselves
A test's values should make its assumed units, boundary, and expected result apparent to a reader.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Make units visible
For a timeout conversion, use 1500 milliseconds and expect 1.5 seconds. A pair of zero values would succeed even if the conversion scale were wrong. Naming units makes the significance of both values clear.
Change one variable when possible
For a display rounding test, retain the same input and compare results at two requested precisions. This identifies display as the parameter under test. Testable program inputs explain how to select cases that distinguish plausible incorrect implementations.[1]
Give the competing roles visibly different data
Testing width and height with a square of size four hides accidental coordinate swaps. Use width seven and height three, and check a point near the right boundary. The values themselves serve as evidence of what the test distinguishes. See row and column indices.
Grid 3 rows × 7 columns
Valid coordinate (row=2, column=6)
Transposed coordinate (row=6, column=2) invalid
Symmetric grid 7×7 would hide this particular swap
Remove unrelated fields from the fixture
A fixture should preserve fields that determine behavior, with clear defaults for others. A named builder can support the case if it keeps relevant values visible. Compare expected output using the same exact coordinate convention as the interface.