Running Tests
The project uses Go’s built-in testing framework with additional tooling for safety and quality.Quick Start
Run all tests with race detection:go test -race ./... which:
- Runs all tests in the project
- Enables the race detector to catch concurrency bugs
- Reports any data races found during test execution
Test Commands
- Make Commands
- Go Commands
Test Structure
Tests are colocated with the code they test, following Go conventions:Writing Tests
Unit Tests
Unit tests verify individual functions in isolation:Table-Driven Tests
Use table-driven tests for testing multiple scenarios:Integration Tests
For tests that require external dependencies like databases:Testing Best Practices
Always use the race detector
Always use the race detector
The race detector catches concurrency bugs:The template’s
make test command includes -race by default.Use t.Helper() for test utilities
Use t.Helper() for test utilities
Mark helper functions to improve error reporting:
Use subtests for organization
Use subtests for organization
Group related tests with
t.Run:Clean up resources
Clean up resources
Always clean up test resources:
Skip slow tests with short mode
Skip slow tests with short mode
Use Run quick tests:
-short flag for quick test runs:Testing Database Code
When testing code that uses the database:Testing HTTP Clients
The template includes a TLS-fingerprinted HTTP client. Test it with mocking:Continuous Integration
The project includes a GitHub Actions workflow for CI:Code Quality Tools
Beyond testing, use these tools to maintain code quality:Linting
Run static analysis:go vet ./... which checks for common mistakes.
Formatting
Ensure consistent code style:go fmt ./... to format all Go files.
Modernization
Update code to use newer APIs:go fix ./... which rewrites code to use current Go idioms.
Coverage Reports
Generate and view test coverage:Benchmarking
Write benchmarks for performance-critical code:Next Steps
Local Setup
Set up your development environment
Database
Learn about testing with databases
