Testing and debugging
go test ships with the language, so a test is a file beside the code that it tests, not a project of its own. These lessons cover test files and table tests, testify, httptest, fakes and mocks, golden files, fuzzing, benchmarks, the race detector and coverage, and the profile that names the hot function. The part ends on go vet and the linters around it.
039
go test, test files and the testing package
a _test.go file, TestXxx, t.Errorf against t.Fatalf, go test -v and a failing test
Open
040
Table tests, subtests and parallel tests
a table of cases, t.Run, t.Parallel and a failure that names its case
Open
041
testify and the libraries around it
require and assert, a suite, and what the helpers add to the testing package
Open
042
Testing HTTP handlers with httptest
httptest.NewRecorder, a handler called directly, httptest.NewServer and a client against it
Open
043
Fakes, stubs and interfaces
an interface at the seam, a fake store, a stub that returns an error and a test that needs no network
Open
044
Mocks: gomock and hand-written doubles
a hand-written mock, gomock in words, expectations and why a fake is often enough
Open
045
Golden files and testdata
a golden file under testdata, an -update flag and a diff that shows what changed
Open
046
Native fuzzing
F.Fuzz, a seed corpus, go test -fuzz and the input that crashes the parser
Open
047
Benchmarks and benchstat
BenchmarkXxx, b.N, -benchmem, the allocs per operation and benchstat in words
Open
048
The race detector and coverage
go test -race, a data race reported with both stacks, -cover and a coverage profile
Open
049
Profiling with pprof
net/http/pprof, a CPU profile, go tool pprof and the hot function it names
Open
050
go vet, staticcheck and golangci-lint
go vet, the checks it runs, staticcheck and golangci-lint named with what this image does not have
Open