Testing
Running tests#
Always run all tests from the repo root with shuffle enabled:
go test -shuffle=on -v ./...
-shuffle=on randomizes test execution order to catch accidental order
dependencies. Go picks and prints the seed automatically.
Test philosophy#
- Black-box testing: tests interact with exported behavior, not implementation details. They create a Model, send key messages, and assert on the resulting state or view output.
- In-memory database: data-layer tests use
:memory:SQLite databases for speed and isolation. - No test order dependencies:
-shuffle=onensures this.
Writing tests#
When adding a new feature:
- Add data-layer tests if you touched Store methods
- Add app-layer tests for key handling, state transitions, and view output
- Use the existing test helpers (
newTestModel,newTestStore, etc.) - Don’t poke into unexported fields – test through the public interface
CI#
Tests run in CI on every push to main and on pull requests, across Linux,
macOS, and Windows. CI uses -shuffle=on and -race to catch ordering dependencies and data
races. Pre-commit hooks catch formatting and lint issues before they reach CI.