Tests are easier to maintain when they run the same way across projects. `go test` ships with Go and needs no separate test framework or configuration file. It compiles a package’s `*_test.go` files into a test executable, runs the tests, and reports the package result. By default, it tests the current directory and keeps successful output brief. section 1.6 section 8.2
Use the runner to narrow a failure or inspect what the tests exercise:
- Name a test `TestXxx(t *testing.T)` in a `*_test.go` file. If no tests run, check the filename and function signature. section 8.1
- Run `go test -v` to see passing tests and their logs; use `go test -run TestMemory` to select a matching test while debugging. section 8.2 section 8.5.4
- Run `go test -cover` to report the percentage of package statements executed. For annotated source, run `go test -coverprofile=coverage.out`, then `go tool cover -html=coverage.out`. section 8.5.7
Coverage is a clue, not a pass
A calculator package reports 93.8% statement coverage. Adding a test for storing a result after an invalid calculation reaches the missed path, but `go test -cover` then reports 100% coverage alongside a failing `TestMemory`: the calculator retained an error and did not store the later valid result. Resetting that error fixes the behavior. Read the coverage percentage together with the test result; executing every statement does not mean the tests passed. section 8.5.7
The same runner supports `go test -bench=.` for benchmarks and `go test -race` to check concurrent code for race conditions during development. Use coverage to find gaps, then write assertions for the behavior those paths should have. section 8.7.1 section 9.6.1 section 8.8
Table 8.1 Types of test functions
| Function name |
Argument type |
Type |
Purpose |
Example |
|---|---|---|---|---|
|
|
|
Test |
Test functionality with pass/fail status |
|
|
|
|
Performance benchmark |
Report performance data and enable profiling |
|
|
|
|
Input fuzzing |
Test inputs and detect edge cases |
|
|
|
(none) |
Testable example |
Document usage and provide additional testing |
|
The function-signature table distinguishes tests from benchmarks, fuzz targets, and testable examples—useful when a function is not being discovered. section 8.1



