Testing Guidelines¶
This project treats testing as a reliability control for clinical data interpretation.
Test Stack¶
- Backend:
pytest(backend/tests) - Frontend unit/component:
Vitest+ React Testing Library - Frontend E2E:
Playwright(CI-first; local only when debugging)
Core Principles¶
- Test behavior, not implementation details.
- Keep assertions tied to ontology/comparability contracts.
- Prefer deterministic fixtures over live external dependencies.
- Add regression tests when fixing bugs.
Backend Test Types¶
Unit (@pytest.mark.unit)¶
Use for isolated logic without network/database I/O.
Integration (@pytest.mark.integration)¶
Use for DB interactions, scraper parsing integration, and service composition.
Full backend suite¶
Frontend Test Types¶
Unit/component suite¶
E2E suite (CI)¶
Default rule: do not run E2E locally unless investigating a specific browser-flow bug. Use GitHub Actions manual dispatch for routine browser verification; the suite was repo-side stabilized on 2026-04-09, but heavy browser coverage remains CI-first to conserve GitHub Actions free-tier minutes.
Coverage and Quality Expectations¶
- Coverage should not regress for changed modules.
- New API routes/services should include happy-path and error-path tests.
- Comparability, divergence warnings, and data-quality logic must remain explicitly tested.
- If a change is hard to test directly, document rationale in PR notes.
- CI retains split frontend/backend coverage artifacts for inspection, but does not depend on a third-party coverage gate.
- Avoid brittle whole-repo coverage gates in local commands when the baseline is intentionally being raised over time.
Naming and Organization¶
- Backend:
test_*.pyunderbackend/tests/unitorbackend/tests/integration - Frontend:
*.test.tsor*.test.tsxinfrontend/tests - Shared backend fixtures:
backend/tests/conftest.py - Shared frontend test utilities:
frontend/tests/test-utils.tsx
Local Verification Matrix¶
Use this as a minimal baseline before opening a PR:
# Backend
ruff check backend/src backend/tests
mypy backend/src
python -m pytest backend/tests
# Frontend
cd frontend
npm run lint
npm run type-check
npm run test:unit
CI Alignment¶
- CI is the source of truth for merge readiness.
- Treat local runs as fast preflight to reduce CI churn.
- If local and CI disagree, prioritize reproducing and fixing CI conditions.
- Frontend and backend coverage artifacts are produced from separate path-scoped workflows and kept as short-lived build artifacts for debugging.
- Playwright remains manual-dispatch in GitHub Actions even after the 2026-04-09 stabilization pass; default merge readiness relies on lint, type-check, unit tests, and build, with browser E2E reserved for explicit verification runs.
Free-Tier CI Conservation (Temporary)¶
When GitHub Actions minutes are constrained:
- Run targeted backend/frontend tests locally before pushing.
- Prefer focused test commands for touched modules during iteration.
- Avoid local Playwright runs unless diagnosing a browser-specific defect.
- Reserve full CI-heavy runs (especially manual-dispatch Playwright) for final verification pushes or targeted browser regressions.