{"id":213,"date":"2026-04-14T09:00:00","date_gmt":"2026-04-14T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/?p=213"},"modified":"2026-10-10T21:20:46","modified_gmt":"2026-10-10T15:50:46","slug":"go-unit-testing-guide","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/","title":{"rendered":"Go Unit Testing Explained for Beginners"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go unit testing is built right into the language, so you can check your code without installing any extra tools. In this post, you will write your first test, use table-driven tests, measure coverage and run benchmarks. Each idea comes with a short example that you can run yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tests live inside packages, so first make sure you understand <a href=\"https:\/\/smitabharat.com\/blog\/go-modules-packages-explained\/\">modules and packages in Go<\/a>. We will also test a function that returns an error, which you learned in <a href=\"https:\/\/smitabharat.com\/blog\/go-error-handling-guide\/\">error handling in Go for beginners<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go Unit Testing?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A unit test is a small piece of code that checks one function gives the right answer. If someone changes that function later and breaks it, the test fails and warns you. So tests act as a safety net for every future change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a car&#8217;s dashboard warning lights. You do not inspect the engine every morning. Instead, the lights tell you the moment something goes wrong. Similarly, Go unit testing tells you right away when your code breaks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Your First Test<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ mathx\/mathx.go\npackage mathx\n\nfunc Add(a, b int) int {\n\treturn a + b\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ mathx\/mathx_test.go\npackage mathx\n\nimport \"testing\"\n\nfunc TestAdd(t *testing.T) {\n\tgot := Add(2, 3)\n\twant := 5\n\tif got != want {\n\t\tt.Errorf(\"Add(2, 3) = %d, want %d\", got, want)\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The test calls the function, then compares what it got with what you want. If they differ, <code>t.Errorf<\/code> marks the test as failed and prints a clear message.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Rules for Test Files<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The file name must end in <code>_test.go<\/code>.<\/li>\n\n\n\n<li>Each test function starts with <code>Test<\/code> and a capital letter.<\/li>\n\n\n\n<li>It takes one parameter: <code>t *testing.T<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Running Tests with go test<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>go test .\/...\n# ok   example.com\/mathx\/mathx   0.002s<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>.\/...<\/code> pattern runs tests in every package of your module. Also, add <code>-v<\/code> to see each test name as it runs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What a Failing Test Looks Like<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>--- FAIL: TestAdd (0.00s)\n    mathx_test.go:9: Add(2, 3) = 5, want 6\nFAIL<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here we changed <code>want<\/code> to 6 on purpose. Go shows the test name, the file, the line number and your message. As a result, you can jump straight to the problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Table-Driven Tests in Go Unit Testing<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>func TestAddTable(t *testing.T) {\n\ttests := &#91;]struct {\n\t\tname string\n\t\ta, b int\n\t\twant int\n\t}{\n\t\t{\"positive\", 2, 3, 5},\n\t\t{\"zero\", 0, 0, 0},\n\t\t{\"negative\", -2, -3, -5},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\tif got := Add(tt.a, tt.b); got != tt.want {\n\t\t\t\tt.Errorf(\"got %d, want %d\", got, tt.want)\n\t\t\t}\n\t\t})\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of writing one test per case, you list all cases in a table. Then a loop runs each row as a subtest with <code>t.Run<\/code>. This is the most popular style in Go projects, as the diagram shows.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-diagram-1024x640.png\" alt=\"Go Unit Testing diagram showing a table of test cases running as named subtests\" class=\"wp-image-215\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Each row in the table becomes its own named subtest, so you see exactly which case passed or failed.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">t.Errorf vs t.Fatal<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>func TestDivideByZero(t *testing.T) {\n\t_, err := Divide(10, 0)\n\tif err == nil {\n\t\tt.Fatal(\"expected an error, got nil\")\n\t}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>t.Errorf<\/code> records a failure but keeps running the test. In contrast, <code>t.Fatal<\/code> stops the test at once. So use Fatal when the rest of the test makes no sense after the failure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Measuring Go Unit Testing Coverage<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>go test -cover .\/mathx\n# ok   example.com\/mathx\/mathx   0.003s   coverage: 75.0% of statements<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Coverage shows how much of your code the tests actually run, which is a key Go unit testing metric. Here the success path of Divide has no test yet, so we are at 75%. Aim for the important paths rather than a perfect 100%.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benchmarks<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>func BenchmarkAdd(b *testing.B) {\n\tfor i := 0; i &lt; b.N; i++ {\n\t\tAdd(2, 3)\n\t}\n}\n\n\/\/ go test -bench=. .\/mathx\n\/\/ BenchmarkAdd-2   1000000000   0.3233 ns\/op<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A benchmark measures speed. Go runs the loop many times and reports the average time per call. Your numbers will differ, because they depend on your machine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Unit Testing Best Practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Write clear failure messages with both got and want.<\/li>\n\n\n\n<li>Use table-driven tests for many similar cases.<\/li>\n\n\n\n<li>Test error paths, not only the happy path.<\/li>\n\n\n\n<li>Run go test -race in your build pipeline.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Go Unit Testing<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Output you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td>[no test files]<\/td><td>The file is not named *_test.go.<\/td><td>Rename it, for example mathx_test.go.<\/td><\/tr><tr><td>[no tests to run]<\/td><td>The function starts with lowercase test.<\/td><td>Rename it to TestAdd.<\/td><\/tr><tr><td>Test passes but code is wrong<\/td><td>The test never checks the result.<\/td><td>Compare got with want.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The first two give no error at all, which makes them easy to miss. Testing questions also come up in my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>, so give them a try.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they are always accurate and up to date.<\/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\/doc\/tutorial\/add-a-test\">Tutorial: Add a test<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/subtests\">Go blog: Using Subtests and Sub-benchmarks<\/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 unit testing needs only the testing package and go test.<\/li>\n\n\n\n<li>Test files end in _test.go, and test names start with Test.<\/li>\n\n\n\n<li>Table-driven tests with t.Run handle many cases cleanly.<\/li>\n\n\n\n<li>Errorf keeps going, while Fatal stops the test.<\/li>\n\n\n\n<li>Use -cover for coverage and -bench for speed.<\/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\">Now you can prove your code works. Next, we will turn Go structs into JSON and back, which every backend developer does daily.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Coming soon: Go JSON Encoding and Decoding Explained<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go unit testing is built right into the language, so you can check your code without installing any extra tools. In this post, you&hellip;<\/p>\n","protected":false},"author":1,"featured_media":214,"comment_status":"closed","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,23,41,21],"swapz_series":[],"class_list":["post-213","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-tutorial","tag-go-unit-testing","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Unit Testing Explained Simply for Beginners<\/title>\n<meta name=\"description\" content=\"Learn Go unit testing with simple examples: write your first test, use table-driven cases, measure coverage and run benchmarks.\" \/>\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-unit-testing-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Unit Testing Explained Simply for Beginners\" \/>\n<meta property=\"og:description\" content=\"Learn Go unit testing with simple examples: write your first test, use table-driven cases, measure coverage and run benchmarks.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-14T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Unit Testing Explained for Beginners\",\"datePublished\":\"2026-04-14T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/\"},\"wordCount\":709,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-unit-testing-guide-featured.png\",\"keywords\":[\"Go Lang\",\"Go Tutorial\",\"Go Unit Testing\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/\",\"name\":\"Go Unit Testing Explained Simply for Beginners\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-unit-testing-guide-featured.png\",\"datePublished\":\"2026-04-14T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:46+00:00\",\"description\":\"Learn Go unit testing with simple examples: write your first test, use table-driven cases, measure coverage and run benchmarks.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-unit-testing-guide-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-unit-testing-guide-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Unit Testing featured image: cards showing a test function, go test and coverage\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-unit-testing-guide\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Unit Testing Explained for Beginners\"}]},{\"@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 Unit Testing Explained Simply for Beginners","description":"Learn Go unit testing with simple examples: write your first test, use table-driven cases, measure coverage and run benchmarks.","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-unit-testing-guide\/","og_locale":"en_US","og_type":"article","og_title":"Go Unit Testing Explained Simply for Beginners","og_description":"Learn Go unit testing with simple examples: write your first test, use table-driven cases, measure coverage and run benchmarks.","og_url":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-14T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:46+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Unit Testing Explained for Beginners","datePublished":"2026-04-14T03:30:00+00:00","dateModified":"2026-10-10T15:50:46+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/"},"wordCount":709,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-featured.png","keywords":["Go Lang","Go Tutorial","Go Unit Testing","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/","url":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/","name":"Go Unit Testing Explained Simply for Beginners","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-featured.png","datePublished":"2026-04-14T03:30:00+00:00","dateModified":"2026-10-10T15:50:46+00:00","description":"Learn Go unit testing with simple examples: write your first test, use table-driven cases, measure coverage and run benchmarks.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-unit-testing-guide-featured.png","width":2400,"height":1260,"caption":"Go Unit Testing featured image: cards showing a test function, go test and coverage"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-unit-testing-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Unit Testing Explained for Beginners"}]},{"@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\/213","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=213"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions\/216"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/214"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=213"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}