liveBook · Manning

Table-driven test

Also called table-driven testing, table test

A table-driven test represents multiple test cases as data records and applies a common testing procedure to each case.

How 6 Manning books explain it

Learn Go with Pocket-Sized Projects

Table-driven testing is a testing technique that represents multiple input-output scenarios as structured test cases processed by shared test logic.

How it is used
Uses table-driven tests to reuse checks across function inputs, expected outputs, and error scenarios.
How deep it goes
Works through case structures, named maps, iteration, subtests, and result comparisons, then applies the pattern to more complex outputs.
Examples
Tests multilingual greetings, JSON file loading, and word-game feedback with repeated characters.
What you can do after
Apply it via Go's testing package to add named scenarios and check results with shared test logic.

Read how Learn Go with Pocket-Sized Projects explains table-driven test →

Go by Example

Table-driven testing is a testing technique that represents multiple test cases as data and executes a common test procedure for each case.

How it is used
Organizes repeated Go function checks into reusable test data and one shared assertion procedure.
How deep it goes
Works through table declaration, iteration, logging, assertions, execution filtering, and fatal-failure limitations before deferring isolation to subtests.
Examples
Demonstrates Parse against full, pathless, and data-scheme URL cases stored in an anonymous struct slice.
What you can do after
Apply it in Go tests to add scenarios as data while reusing one test procedure.

Read how Go by Example explains table-driven test →

Shipping Go: Develop, deliver, discuss, design, and go again

Table-driven testing defines multiple test cases as structured data and executes a common test procedure for each case.

How it is used
Organizes repeated test scenarios so cases can be added and code refactored quickly.
How deep it goes
Works through refactoring repeated tests into case data, running them, and adding edge cases to drive fixes.
Examples
Uses translator cases and HTTP endpoint cases with expected response statuses and translations.
What you can do after
Apply it using Go’s testing package to extend translation and HTTP response tests.

Read how Shipping Go: Develop, deliver, discuss, design, and go again explains table-driven test →

100 Go Mistakes and How to Avoid Them

A table-driven test organizes multiple test cases as data and applies shared testing logic to each case.

How it is used
Reduces duplicated unit-test code by representing similar cases as data and applying one testing procedure.
How deep it goes
Explains case tables, subtests, selective execution, and parallel-test loop-variable handling, without broader test design.
Examples
Uses newline-suffix removal cases covering empty, newline, carriage-return/newline, repeated-newline, and unchanged inputs.
What you can do after
Apply via Go subtests by defining case data once and reusing shared invocation and comparison logic.

Read how 100 Go Mistakes and How to Avoid Them explains table-driven test →

Go in Action, Second Edition

A table-driven test represents multiple test cases as data records and runs a common test procedure over them.

How it is used
Simplifies repetitive Go tests by separating varying case data from shared execution and assertion logic.
How deep it goes
Explains struct design, slice construction, looping, logging, and maintenance benefits, but does not develop advanced table-test variations.
Examples
Uses Calculator operations and HTTP GET, POST, and unsupported-method handler cases as concrete test tables.
What you can do after
Apply the pattern by defining case records, iterating over them, logging inputs, and asserting each result with go test.

Read how Go in Action, Second Edition explains table-driven test →

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.

How it is used
Organizes unit tests around multiple input and expected-output cases instead of relying on manual output inspection.
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.

Read how Go in Practice, Second Edition explains table-driven test →

What to know first

Related concepts

Questions about table-driven test

What is table-driven test?

A table-driven test represents multiple test cases as data records and applies a common testing procedure to each case.

Which Manning books explain table-driven test?

Learn Go with Pocket-Sized Projects, Go by Example, Shipping Go: Develop, deliver, discuss, design, and go again, 100 Go Mistakes and How to Avoid Them, Go in Action, Second Edition and Go in Practice, Second Edition.

What should I know before learning table-driven test?

Manning books that teach table-driven test usually introduce slicing, software testing, benchmark and test coverage first.

What is the difference between table-driven test and Fatalf?

A table-driven test represents multiple test cases as data records and applies a common testing procedure to each case. Fatalf is a testing method that records a formatted failure message and immediately terminates the calling test function.

What is table-driven test also called?

Table-driven test is also called table-driven testing or table test.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.