Module 12 Β· Testing β Lesson 2 of 3 Β· ~9 min
Table-driven tests
One test, many cases
You rarely want to check just one input. PriceLabel should be right for 2500, for 0, for an odd number of cents. Copy-pasting the got/want block three times is noisy and easy to get wrong.
Go's answer is the table-driven test: list your cases as data in a slice, then loop over them running the same assertion for each. It's the single most common Go testing pattern β you'll see it in the standard library itself.