This is a course for those who say, “I know Go syntax, but I don’t know how to write tests.” When you start learning Go, basics like functions, structs, and interfaces come naturally. However, when it’s time to write tests, many people freeze, wondering, “Where do I start?” or “Am I doing this right?” Testing follows specific patterns; once you master these patterns in order, anyone can write them. In this course, you will systematically learn how to write test code using Go’s standard testing package through 30 hands-on exercises. Rather than just watching videos, you will solve problems to ensure that what you understand mentally translates naturally into code.
What You Will Learn:
- Section 1: Basic Test StructureCover the essentials: naming rules for test functions/files, the difference between t.Error and t.Fatal, and how to test functions that return errors.
- Section 2: Table-Driven TestsLearn the widely-used Go pattern for managing multiple test cases in slices. Use t,Run for subtests to quickly identify failures, and learn how to handle boundary values and compare slices or maps.
- Section 3: Test OrganizationMaster techniques for robust testing: setup/teardown with TestMain, resource cleanup with t.Cleanup, and handling temporary files or environment variables with t.TempDir and t.Setenv. We also cover parallel execution with t.Parallel.
- Section 4: Interfaces & Dependency InjectionHard-to-test code often stems from external dependencies (time, files, APIs). Learn to use interfaces for abstraction and swap dependencies with manual stubs. You’ll also explore patterns using io.Reader and io.Writer.
- Section 5: HTTP TestingLearn how to test Web applications using httptest.ResponseRecorder for handlers, httptest.NewServer for mocking external APIs, and methods for validating JSON responses.
- Section 6: Comprehensive ExerciseThe final challenge combines everything. You will implement tests for a simple REST API using table-driven tests, httptest, and stubs, while checking coverage with go test -cover.






