GO

Go Testing

Used in 204 go projects (avg ★1042)

Go
Testing
Default
Used by 204 projects

Details

Language / Topic
goGo
Category
Testing

Rules

balanced
- Run all tests with `go test ./...`. Use `go test -cover` to check coverage.
- Write unit tests in `*_test.go` files using the `testing` package.
- Use `testify/assert` for readable assertions: `assert.Equal(t, expected, actual)` — it provides better failure messages than manual `if` checks.
- Use `go test -race` to detect data races in concurrent code.
- Use `go test -short` to skip slow tests during development. Use `-v` for verbose output.
- Mock external dependencies for isolation — use interfaces and inject test doubles.
- Add tests when modifying logic. Run `go test -count=1` to disable test caching when debugging flaky tests.