- Catch regressions early with fast, deterministic tests.
- Keep local developer feedback under 2 minutes for default test commands.
- Separate unit, integration, and smoke concerns so failures are easy to triage.
- Establish a CI path that can grow without making every PR slow.
- Prefer pure-function and boundary tests first (lower brittleness).
- Mock external systems at unit level; use real dependencies in integration level.
- Keep smoke checks focused on service availability and one core user flow.
- Add tests with each bug fix or feature in the closest layer that can catch it.
Tooling:
go test(stdlibtestingpackage)httptestfor HTTP handler tests- temporary SQLite databases for repository/service integration tests
Recommended layers:
- Unit (
backend/internal/**/_test.go)
- Test helpers, transformations, validation, and in-memory logic.
- No filesystem/network/process dependencies.
- Integration (
backend/internal/**/_test.go, build tag optional)
- Exercise repository + service with temp DB and real migrations.
- Exercise API handlers with
httptestand real JSON payloads.
- Smoke (
scripts/api-smoke.ps1and future shell equivalent)
- Run against a started app instance.
- Validate
/health, camera CRUD happy path, and stream-status endpoint response shape.
Tooling:
- Vitest (
frontend/vitest.config.ts) - Node environment for API/client utility tests (fast baseline)
- Later: jsdom + React Testing Library for component behavior
Recommended layers:
- Unit (
frontend/src/**/*.test.ts)
- API wrappers, formatters, query builders, state helpers.
- Mock
fetch; assert request method/headers/body and error mapping.
- Integration (
frontend/src/**/*.test.tsx)
- Render page-level flows with mocked API via MSW.
- Cover loading, empty, error, and success states.
- Smoke (optional CI job)
- Build app and run a minimal browser script (Playwright) against a running backend.
Tooling:
pytest- monkeypatch/stubs for
onnxruntimein unit tests - FastAPI
TestClientin integration tests
Recommended layers:
- Unit (
ai_worker/tests/unit_*.pyorai_worker/tests/test_*.py)
- Image preprocessing, NMS logic, response shaping, threshold handling.
- Avoid model file dependency by stubbing runtime/session objects.
- Integration (
ai_worker/tests/integration_*.py)
/healthand/detectrequest/response validation with generated images.- Use a controlled fake inference output.
- Smoke (compose)
docker compose upthen verify AI worker/healthand backend detector health endpoint.
- Backend:
backend/internal/<domain>/*_test.go - Frontend:
frontend/src/<domain>/*.test.ts(x) - AI worker:
ai_worker/tests/test_*.py
Naming:
- Use behavior-oriented names (
TestBufferKeepsLastNLines,test_nms_filters_overlapping_boxes). - Keep each test focused on one behavior.
- Add minimal runnable tests in all three subsystems.
- Add local test commands and baseline config.
- Backend: add repository+service integration tests for cameras/settings/detections.
- Frontend: add integration tests for
DashboardandCameraViewwith mocked network. - AI worker: add
/detectendpoint tests for empty upload, invalid mime, valid image response shape.
- Add coverage reporting per subsystem and enforce floor on changed files.
- Add flaky-test guardrails (timeouts, deterministic fixtures, no live-network tests).
- Add smoke tests in CI for compose deployment and key API contracts.
- Run nightly extended integration suite (non-blocking on regular PRs).
Run separate jobs so failures are isolated:
backend-test
cd backend && go test ./...
frontend-test
cd frontend && npm ci && npm run test
ai-worker-test
cd ai_worker && python -m pip install -r requirements.txt -r requirements-dev.txt && pytest
smoke(optional required on main branch)
- Start services (compose or local)
- Run health/API smoke checks
Suggested policy:
- PR required: backend/frontend/ai unit tests
- Main/nightly: integration + smoke
- Backend:
backend/internal/logs/buffer_test.go - Frontend:
frontend/src/api/recordings.test.ts,frontend/src/api/settings.test.ts - AI worker:
ai_worker/tests/test_main_helpers.py
These tests are intentionally low-coupling and fast to establish a reliable base before broader integration coverage.