Skip to content

Testing

  • 70% Unit Tests — fast, isolated, test business logic
  • 20% Integration Tests — API endpoints + database
  • 10% E2E Tests — critical user flows
Terminal window
cd backend
pytest # Run all tests
pytest -v # Verbose output
pytest -m unit # Only unit tests
pytest --cov=app # With coverage

We use SQLite for local testing (fast, no Docker dependency) with a PortableJSON type adapter. This is a pragmatic trade-off:

AspectSQLite (Current)PostgreSQL (Better)
Speed2 seconds10-30 seconds
SetupNoneDocker required
Accuracy80%100% matches production

Migration path: Testcontainers with real PostgreSQL when the project matures.

# Use dependency_overrides, NOT unittest.mock.patch
app.dependency_overrides[get_db] = _override_get_db
app.dependency_overrides[get_current_active_user] = _override_auth
yield TestClient(app)
app.dependency_overrides.clear()

Systematic tests for AI model outputs — accuracy, hallucination rate, cost, latency. Custom eval framework with:

  • Pydantic-typed eval datasets
  • Domain-specific metrics (calorie error, protein error)
  • Multi-model comparison (OpenAI vs Claude vs Gemini)
  • CI/CD integration (trigger with [evals] in commit message)

See the Evals page for the full guide.

Tests run on every push/PR via GitHub Actions:

  1. Backend pytest (Python 3.9, 3.10, 3.11)
  2. Frontend typecheck + lint
  3. Model evals (main branch only)
  4. Build check

Current coverage threshold: 30% (goal: 80%).