Testing
Run your App's tests from the Project root. Start with the service tests from Your First Route, then check photo persistence and photo job dispatch as you add those features.
go test ./...Expected result: packages report ok or [no test files]. A failure identifies the package and test to inspect first. GoForj also generates tests for enabled framework components such as lifecycle, readiness, and database connections.
Choose a Test Layer
Start with the test that proves the behavior you changed.
| Behavior to prove | Start with | Add a broader test when |
|---|---|---|
| Services, repositories with fakes, and pure domain behavior | Unit Tests with go test ./... | Generated wiring or a real backend changes the result |
| Controllers, route groups, and generated HTTP behavior | HTTP Tests with httptest | Listener or full-App behavior is the point |
| Console commands | Command Tests | Generated registration or runtime composition matters |
| Job handlers and dispatch | Job and Queue Tests | Retries, worker lifecycle, shutdown, or backend behavior matters |
| Event publishing and subscribers | Event Tests | Delivery through an external backend matters |
| Cache and storage behavior | Cache and Storage Tests | Driver-specific semantics matter |
| Database, external backends, or App boundaries | Integration Tests with go test -tags=integration ./... | You need to verify the App's runtime setup too |
Keep Domain Behavior Direct
Test services and the code called by jobs, event subscribers, and scheduled tasks through their constructors. Use fakes for isolated service rules and temporary local backends for persistence or delivery checks. Keep generated registration and runtime startup in tests of those boundaries.
Local infrastructure drivers can keep broader tests small:
- use
inprocfor event delivery - use a compiled
syncorworkerpoolqueue driver for local delivery - use
nullwhen no-op queue behavior is the contract
Maintainer Workflows
When you change the GoForj templates or generators, run the rendered Project smoke and integration tests against a disposable App.
Related Sections
- Getting Started introduces the first local application path.
- Operations explains runtime behavior that integration tests should verify.