Why we test
Tests exist to give confidence. Confidence to ship changes quickly, confidence that refactoring will not break production, confidence that the system behaves as expected. A test suite with 90 percent coverage that misses critical edge cases is less valuable than one with 60 percent coverage that catches real bugs. We prioritize quality over quantity. A single well-designed test that validates complex business logic is worth more than a dozen tests that exercise trivial code paths. When writing tests, ask what could go wrong in production that this test would catch.What to test
Invest testing effort where bugs would hurt most. High value targets: Business logic with complex conditionals, error handling paths, concurrent code with race potential, security sensitive operations, data transformations that could silently corrupt. Lower value targets: Simple getters and setters, straightforward pass-through functions, code that delegates to well-tested libraries. Skip entirely: Tests that verify the programming language works. Ask what bug this test would catch that the compiler, a code review, or a more meaningful test would not.Testing observability
Do not verify every log line or metric increment. Test metrics that drive alerts or SLOs. Test that error conditions produce the logs operators need for debugging.Go testing
All Go tests usegithub.com/stretchr/testify/require for assertions.
We build and test with Bazel rather than go test directly. Bazel provides hermetic builds, intelligent caching, and precise dependency tracking.
Test organization
Tests live alongside the code they test. A filecache.go has its tests in cache_test.go in the same directory.
For integration tests that require substantial setup or external dependencies, create an integration/ subdirectory when it improves clarity.
Bazel requires each test target to declare a size that determines its timeout and resource allocation. Unit tests should be small. Integration tests that spin up containers should be large.
Writing test helpers
Every helper function must callt.Helper() as its first line.
Resource cleanup
Tests that acquire resources must clean them up. Uset.Cleanup() instead of defer.

