{"id":427,"date":"2026-05-20T09:00:00","date_gmt":"2026-05-20T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/"},"modified":"2026-05-20T09:00:00","modified_gmt":"2026-05-20T03:30:00","slug":"go-table-driven-tests-benchmarks","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/","title":{"rendered":"Go Table-Driven Tests and Benchmarks Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go table-driven tests let you check many inputs with one short piece of test code. In this post, you will learn how to list cases in a slice. You will also run each one as a subtest and read the results. Then we will add a benchmark, so you can measure speed with real numbers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/\">Go unit testing for beginners<\/a>, where you wrote your first test. We also use slices and structs, which you met in <a href=\"https:\/\/smitabharat.com\/blog\/go-slices-arrays-explained\/\">Go slices and arrays<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-structs-beginners-guide\/\">Go structs explained<\/a>. Because of that, the code here should feel familiar. However, every new idea is explained step by step.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Go Table-Driven Tests?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In short, Go table-driven tests keep all test cases in a list, called a table. Each row holds a name, the input and the result you expect. Then one loop runs every row through the same check. As a result, the test code stays short even when the table grows.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a teacher with an answer sheet. The teacher keeps one marking process and one sheet of questions with answers. So if you add a question, the process stays the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go developers love this style. In fact, the Go team itself uses it all over the standard library. As a result, you will see it in almost every open source Go project. For that reason, learning Go table-driven tests early will also help you read other people&#8217;s code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Table-Driven Tests Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Without a table, people copy and paste a test function again and again. As a result, the file quickly becomes messy. So here is what Go table-driven tests fix.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Less repeated code<\/strong>: the check is written once, and the data changes.<\/li>\n\n\n\n<li><strong>Easy to add cases<\/strong>: a new edge case is one new line.<\/li>\n\n\n\n<li><strong>Clear failures<\/strong>: each case has a name, so you see exactly which one broke.<\/li>\n\n\n\n<li><strong>Better coverage<\/strong>: seeing all cases together helps you spot what is missing.<\/li>\n\n\n\n<li><strong>Easy review<\/strong>: teammates can read the table like a list of rules.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Because of this, tables are the standard way to test pure functions in Go. A pure function is one that returns the same result for the same input and changes nothing outside itself. Therefore, it is the easiest kind of code to put in a table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Table-Driven Tests Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Go table-driven tests, you first describe each case as a struct. After that, you put the structs in a slice. Then you loop over the slice and call <code>t.Run<\/code> with the case name. Finally, inside each subtest you compare the real result with the wanted one and call <code>t.Errorf<\/code> when they differ.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-1-1024x640.png\" alt=\"Go Table-Driven Tests diagram showing a table of named cases feeding one loop that runs subtests\" class=\"wp-image-400\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">A table of named cases feeds one loop. Each row becomes a subtest that calls the function, compares the result and reports a pass or fail.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">However, a failed row does not stop the others. As a result, one run shows you every broken case at once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Parts of a Test Table<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A table needs only three kinds of fields. So the table below lists them, and it adds a short example for each.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Field<\/th><th>Purpose<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td><code>name<\/code><\/td><td>Names the subtest<\/td><td><code>\"extra spaces\"<\/code><\/td><\/tr><tr><td><code>input<\/code><\/td><td>Value passed to the function<\/td><td><code>\"  Go   is  fun  \"<\/code><\/td><\/tr><tr><td><code>want<\/code><\/td><td>Result you expect<\/td><td><code>\"go-is-fun\"<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes you also add <code>wantErr bool<\/code> when the function can return an error. Meanwhile, keep the struct small so the table stays easy to read. For example, a function that parses a date would have one row for a good date and one row for &#8220;31 February&#8221;, with <code>wantErr<\/code> set to true.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Subtests with t.Run<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>t.Run<\/code> function creates a named subtest. Because of this, failure messages show the exact case, such as <code>TestMake\/punctuation<\/code>. You can also run a single case with the <code>-run<\/code> flag, which saves time when you debug.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Table-Driven Tests vs Separate Test Functions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can write one test function per case, or you can write one table. Both work, but they feel different, as the table below shows. For example, adding a tenth case to a table takes seconds.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Table-driven<\/th><th>Separate functions<\/th><\/tr><\/thead><tbody><tr><td>Adding a case<\/td><td>One new line<\/td><td>A new function<\/td><\/tr><tr><td>Repeated code<\/td><td>Very little<\/td><td>A lot<\/td><\/tr><tr><td>Failure message<\/td><td>Shows the case name<\/td><td>Shows the function name<\/td><\/tr><tr><td>Run one case<\/td><td><code>-run Test\/name<\/code><\/td><td><code>-run TestName<\/code><\/td><\/tr><tr><td>Best for<\/td><td>Many inputs, one rule<\/td><td>Cases with very different setup<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-2-1024x640.png\" alt=\"Go Table-Driven Tests diagram comparing a table with separate test functions\" class=\"wp-image-401\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Table-driven tests share one check across many rows, while separate test functions repeat the check for every case.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when should you use which? Use a table when the steps are the same and only the data changes. On the other hand, use separate functions when each case needs its own setup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Table-Driven Tests Hands-On: Test a Slug Function<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s test a small function that turns a title into a URL slug. For example, it turns &#8220;Hello World&#8221; into &#8220;hello-world&#8221;. To do this, it lowercases the text, keeps letters and digits, and joins words with dashes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Function<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, here is the code that we want to test.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package slug\n\nimport (\n\t\"strings\"\n\t\"unicode\"\n)\n\n\/\/ Make turns a title into a URL-friendly slug.\nfunc Make(title string) string {\n\tvar b strings.Builder\n\tlastDash := true \/\/ avoids a leading dash\n\tfor _, r := range strings.ToLower(title) {\n\t\tif unicode.IsLetter(r) || unicode.IsDigit(r) {\n\t\t\tb.WriteRune(r)\n\t\t\tlastDash = false\n\t\t} else if !lastDash {\n\t\t\tb.WriteByte('-')\n\t\t\tlastDash = true\n\t\t}\n\t}\n\treturn strings.TrimSuffix(b.String(), \"-\")\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: The Table-Driven Test<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we write the test in a file named <code>slug_test.go<\/code>. Each row is one scenario. Also, we include tricky ones, such as an empty string.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package slug\n\nimport \"testing\"\n\nfunc TestMake(t *testing.T) {\n\ttests := []struct {\n\t\tname  string\n\t\tinput string\n\t\twant  string\n\t}{\n\t\t{\"simple words\", \"Hello World\", \"hello-world\"},\n\t\t{\"extra spaces\", \"  Go   is  fun  \", \"go-is-fun\"},\n\t\t{\"punctuation\", \"Go: Tables &amp; Tests!\", \"go-tables-tests\"},\n\t\t{\"digits kept\", \"Top 10 Go Tips\", \"top-10-go-tips\"},\n\t\t{\"empty string\", \"\", \"\"},\n\t\t{\"only symbols\", \"!!!\", \"\"},\n\t}\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tgot := Make(tt.input)\n\t\t\tif got != tt.want {\n\t\t\t\tt.Errorf(\"Make(%q) = %q, want %q\", tt.input, got, tt.want)\n\t\t\t}\n\t\t})\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s walk through the key lines. First, the anonymous struct slice is the table. Then the <code>for<\/code> loop visits each row, and <code>t.Run<\/code> starts a subtest named after the row. Finally, <code>t.Errorf<\/code> reports the input, the real result and the wanted result, so you can fix the bug quickly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Run the Tests<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now run <code>go test -v<\/code>. As a result, you should see the real output below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>=== RUN   TestMake\n=== RUN   TestMake\/simple_words\n=== RUN   TestMake\/extra_spaces\n=== RUN   TestMake\/punctuation\n=== RUN   TestMake\/digits_kept\n=== RUN   TestMake\/empty_string\n=== RUN   TestMake\/only_symbols\n--- PASS: TestMake (0.00s)\n    --- PASS: TestMake\/simple_words (0.00s)\n    --- PASS: TestMake\/extra_spaces (0.00s)\n    --- PASS: TestMake\/punctuation (0.00s)\n    --- PASS: TestMake\/digits_kept (0.00s)\n    --- PASS: TestMake\/empty_string (0.00s)\n    --- PASS: TestMake\/only_symbols (0.00s)\nPASS<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that Go replaces spaces in case names with underscores. Next, let&#8217;s see a failure by changing one wanted value. For example, if you expect <code>go-tables-and-tests<\/code>, the output points straight to the broken row.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>--- FAIL: TestMake (0.00s)\n    --- FAIL: TestMake\/punctuation (0.00s)\n        slug_test.go:22: Make(\"Go: Tables &amp; Tests!\") = \"go-tables-tests\", want \"go-tables-and-tests\"\nFAIL<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To run only one case, type <code>go test -v -run \"TestMake\/extra\"<\/code>. Also, <code>go test -cover<\/code> shows the share of code your tests touch. In our case, it reports 100.0% of statements, because every branch has a row.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benchmarks: Measure Speed in Go<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A benchmark measures how fast a function runs. Benchmark names start with <code>Benchmark<\/code> and take a <code>*testing.B<\/code>. Because speed varies, Go decides how many times to loop and stores that number in <code>b.N<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func BenchmarkMake(b *testing.B) {\n\tfor i := 0; i &lt; b.N; i++ {\n\t\tMake(\"Go: Tables &amp; Tests for Beginners\")\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run it with <code>go test -bench=. -benchmem -run=^$<\/code>. The <code>-run=^$<\/code> part skips normal tests, so only the benchmark runs. Then you will see output like the line below from our machine.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BenchmarkMake-2   \t 3075823\t       492.2 ns\/op\t      88 B\/op\t       4 allocs\/op<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s read it from left to right. First, the function ran about 3 million times. Then each call took roughly 492 nanoseconds, used 88 bytes and made 4 memory allocations. Your numbers will differ, because they depend on your computer. However, the pattern is what matters: compare results before and after a change on the same machine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Table-Driven Tests<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Missing case names<\/strong>: unnamed cases make failures hard to find. So always fill the <code>name<\/code> field in every Go table-driven tests file you write.<\/li>\n\n\n\n<li><strong>Only happy paths<\/strong>: bugs hide in empty, huge and odd inputs. Therefore, add edge cases to every table.<\/li>\n\n\n\n<li><strong>Using the loop variable in parallel tests<\/strong>: older Go versions shared it between subtests. Since Go 1.22 each loop step has its own copy, but check your <code>go.mod<\/code> version.<\/li>\n\n\n\n<li><strong>Giant tables with long setup<\/strong>: the table becomes hard to read. Instead, split cases into groups.<\/li>\n\n\n\n<li><strong>Benchmarking once<\/strong>: one run is noisy. So repeat with <code>-count=5<\/code> and compare the results.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Table-Driven Tests<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use descriptive names<\/strong>, because they act as living documentation.<\/li>\n\n\n\n<li><strong>Put edge cases first or last<\/strong>, so reviewers can find them quickly.<\/li>\n\n\n\n<li><strong>Print the input in the failure message<\/strong>, since it saves debugging time.<\/li>\n\n\n\n<li><strong>Keep one assertion style<\/strong>, because it makes every case read the same way.<\/li>\n\n\n\n<li>**Run <code>go test -race<\/code> in CI**, because it also catches hidden data races.<\/li>\n\n\n\n<li><strong>Benchmark only hot code<\/strong>, since measuring everything wastes time.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise Go table-driven tests, write a function <code>IsPalindrome(s string) bool<\/code> that ignores case and spaces. Then create a table with at least six cases. Good examples are &#8220;Level&#8221;, &#8220;A man a plan a canal Panama&#8221; and an empty string.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: build a cleaned slice of runes first. After that, compare it with its reverse. Finally, add a benchmark and compare a short string with a long one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages explain the testing package, and they also describe the table-driven style in detail.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/testing\">testing package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/wiki\/TableDrivenTests\">Go Wiki: TableDrivenTests<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/doc\/tutorial\/add-a-test\">Add a test: Go tutorial<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go table-driven tests keep every case in a slice of structs.<\/li>\n\n\n\n<li>One loop with <code>t.Run<\/code> turns each row into a named subtest.<\/li>\n\n\n\n<li>A failed row does not stop the other rows.<\/li>\n\n\n\n<li>Use <code>-run<\/code>, <code>-cover<\/code> and <code>-v<\/code> to control and inspect a test run.<\/li>\n\n\n\n<li>Benchmarks use <code>b.N<\/code> and report time, bytes and allocations per call.<\/li>\n\n\n\n<li>Add edge cases such as empty strings and symbols to every table.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By now, you can test pure functions with confidence. However, most real services also have HTTP handlers. So next, we will test full handlers without starting a real server, using the <code>httptest<\/code> package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up: <a href=\"https:\/\/smitabharat.com\/blog\/go-httptest-handlers\/\">Go httptest for testing HTTP handlers<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go table-driven tests let you check many inputs with one short piece of test code. In this post, you will learn how to list&hellip;<\/p>\n","protected":false},"author":1,"featured_media":399,"comment_status":"","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,78,77],"swapz_series":[],"class_list":["post-427","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-testing","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Table-Driven Tests and Benchmarks Explained<\/title>\n<meta name=\"description\" content=\"Learn Go table-driven tests step by step: list cases in a slice, run subtests with t.Run, add benchmarks and read real test output.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Table-Driven Tests and Benchmarks Explained\" \/>\n<meta property=\"og:description\" content=\"Learn Go table-driven tests step by step: list cases in a slice, run subtests with t.Run, add benchmarks and read real test output.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-20T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Table-Driven Tests and Benchmarks Explained\",\"datePublished\":\"2026-05-20T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/\"},\"wordCount\":1460,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-table-driven-tests-benchmarks-featured.png\",\"keywords\":[\"Go Lang\",\"Go Testing\",\"Intermediate\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/\",\"name\":\"Go Table-Driven Tests and Benchmarks Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-table-driven-tests-benchmarks-featured.png\",\"datePublished\":\"2026-05-20T03:30:00+00:00\",\"description\":\"Learn Go table-driven tests step by step: list cases in a slice, run subtests with t.Run, add benchmarks and read real test output.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-table-driven-tests-benchmarks-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-table-driven-tests-benchmarks-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go table-driven tests featured image: named cases, subtests and a benchmark\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-table-driven-tests-benchmarks\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Table-Driven Tests and Benchmarks Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Table-Driven Tests and Benchmarks Explained","description":"Learn Go table-driven tests step by step: list cases in a slice, run subtests with t.Run, add benchmarks and read real test output.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/","og_locale":"en_US","og_type":"article","og_title":"Go Table-Driven Tests and Benchmarks Explained","og_description":"Learn Go table-driven tests step by step: list cases in a slice, run subtests with t.Run, add benchmarks and read real test output.","og_url":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-20T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Table-Driven Tests and Benchmarks Explained","datePublished":"2026-05-20T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/"},"wordCount":1460,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-featured.png","keywords":["Go Lang","Go Testing","Intermediate"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/","url":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/","name":"Go Table-Driven Tests and Benchmarks Explained","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-featured.png","datePublished":"2026-05-20T03:30:00+00:00","description":"Learn Go table-driven tests step by step: list cases in a slice, run subtests with t.Run, add benchmarks and read real test output.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-table-driven-tests-benchmarks-featured.png","width":2400,"height":1260,"caption":"Go table-driven tests featured image: named cases, subtests and a benchmark"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-table-driven-tests-benchmarks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Table-Driven Tests and Benchmarks Explained"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/427","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=427"}],"version-history":[{"count":0,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/399"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=427"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}