Table-Driven Tests
A table-driven test enumerates inputs and expected outcomes in rows while sharing one execution and assertion procedure.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Choose varied rows
For a shipping classification, include ordinary affordable, boundary qualifying, and over-limit cases. Give each row a descriptive label to identify the case in output. Start from a decision table if the operation depends on multiple rules.
Keep the expected answers independent
If the implementation computes expected and actual results by the same formula, a shared mistake can pass. For a small set, write the results directly after checking them by hand. Function postconditions give you additional properties to assert.[1]
Give each case a reason for being present
A parser for nonnegative integers can test zero, a positive number, a negative number, whitespace and an invalid literal. Each row contains input and expected outcome, plus a case name identifying the rule. See boundary data.
zero: "0" → 0
positive: "18" → 18
below minimum: "-1" → range error
invalid spelling: "many" → parse error
Use a table when the action stays the same
A row needing a different setup, state sequence or concurrency condition may deserve a separate test. If a case fails, the output should identify its input and expected outcome. Ensure every row builds fresh mutable data when required.