liveBook · Manning

Table-driven test

As explained in Go in Practice, Second Edition

A test table is a collection of input and expected-result records used to exercise multiple conditions against a test target.

A table-driven test replaces error-prone manual checking with a slice of input and expected-result records. The test runs the target against each record and reports mismatches through Go's testing package. section 6.3.1

How Go in Practice, Second Edition covers it

How deep it goes
Defines the table, iteration, assertion, failure inspection, and case expansion, but does not cover subtests or benchmarks.
Examples
Uses Fizz Buzz cases for inputs 37, 5, and 12, including expected strings and failing or passing go test output.
What you can do after
Diagnose implementation errors and extend coverage by adding input and expected-result records.
How it connects
Connects unit testing with the Go testing package and the go test command.

Also explained in

Compare how 6 books explain table-driven test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.