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
Table-driven test
A test table is a collection of input and expected-result records used to exercise multiple conditions against a test target.
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
-
Learn Go with Pocket-Sized ProjectsTable-driven testing is a testing technique that represents multiple input-output scenarios as structured test cases processed by shared test logic.
-
Go by ExampleTable-driven testing is a testing technique that represents multiple test cases as data and executes a common test procedure for each case.
-
Shipping Go: Develop, deliver, discuss, design, and go againTable-driven testing defines multiple test cases as structured data and executes a common test procedure for each case.
-
100 Go Mistakes and How to Avoid ThemA table-driven test organizes multiple test cases as data and applies shared testing logic to each case.
-
Go in Action, Second EditionA table-driven test represents multiple test cases as data records and runs a common test procedure over them.
Compare how 6 books explain table-driven test →
Related concepts
- testuses · A test is a procedure or check that evaluates behavior using specified inputs or evidence against expected results or criteria.
- structuses · A struct is a composite data type or structure that groups related fields or values into a single unit.
- subtestuses · A subtest is an independently named test execution nested within a parent test and reported separately.
- Mapused by · A map is an associative data structure that stores key-value pairs and supports retrieving values by key.
- Fatalfcontrasts with · Fatalf is a testing method that records a formatted failure message and immediately terminates the calling test function.
- slicinguses · Slicing selects or partitions a portion of an indexed sequence or multidimensional array, often along specified indices or dimensions.
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.





