This document provides an overview of Ampel's testing strategy and links to detailed guides.
# Run all tests (backend + frontend)
make test
# Run only backend tests
make test-backend
# Run only frontend tests
make test-frontend| Document | Description |
|---|---|
| BACKEND.md | Rust testing: unit tests, integration tests, TestDb, fixtures |
| FRONTEND.md | React testing: Vitest, React Testing Library, component tests |
| CI.md | CI/CD pipeline: GitHub Actions, cargo-nextest profiles, artifacts |
- Test Organization: Unit tests live alongside code, integration tests in
tests/directories - Isolation: Each test runs in a completely isolated environment
- Fast Feedback: SQLite for quick unit tests, PostgreSQL for comprehensive integration tests
- Real Data: Use actual database queries, not mocks, for integration tests
- User-centric: Test from the user's perspective, not implementation details
- Framework:
cargo test/cargo-nextest - Coverage:
cargo-llvm-cov(LLVM source-based coverage, 5-10x faster than tarpaulin) - Database: PostgreSQL (integration) / SQLite (unit tests)
# Quick unit tests
cargo nextest run --profile fast
# Full integration tests
DATABASE_URL=postgres://... cargo nextest runSee BACKEND.md for complete details.
- Framework: Vitest
- Component Testing: React Testing Library
- Coverage: Built-in Vitest coverage
cd frontend
pnpm test -- --run # Run tests
pnpm test # Watch mode
pnpm test -- --run --coverage # With coverageSee FRONTEND.md for complete details.
- Platform: GitHub Actions
- Test Runner: cargo-nextest
- Coverage: Codecov integration
Tests run automatically on all PRs and pushes to main/develop.
See CI.md for complete details.
crates/
├── ampel-api/
│ ├── src/**/*.rs # Unit tests in #[cfg(test)] modules
│ └── tests/ # API integration tests
├── ampel-db/
│ └── tests/
│ ├── common/ # TestDb, fixtures
│ └── integration/ # Database integration tests
└── ampel-providers/
└── tests/ # Provider integration tests
frontend/
├── src/
│ ├── components/**/__tests__/ # Component tests
│ ├── hooks/**/*.test.ts # Hook tests
│ └── utils/**/*.test.ts # Utility tests
└── tests/
└── setup.ts # Global test setup
Target: 80% code coverage across the project
Coverage is automatically tracked via Codecov and reported on all pull requests. We use:
- Backend: cargo-llvm-cov for Rust code coverage (LLVM source-based instrumentation)
- Frontend: Vitest's built-in coverage (v8 provider)
- CI Integration: Automatic coverage reporting on PRs with thresholds
# Run all tests with coverage reports
make test-coverage
# Backend coverage only
make test-backend-coverage
# Frontend coverage only
make test-frontend-coverage# Auto-installs cargo-llvm-cov if not present
cargo llvm-cov \
--all-features \
--workspace \
--html \
--output-dir coverage
# View HTML report
open coverage/html/index.html # macOS
xdg-open coverage/html/index.html # Linuxcd frontend
# Run tests with coverage
pnpm test -- --run --coverage
# View HTML report
open coverage/index.html # macOS
xdg-open coverage/index.html # LinuxOur Codecov configuration enforces these thresholds:
| Component | Target | Threshold | Description |
|---|---|---|---|
| Project | 80% | ±2% | Overall project coverage |
| Patch (New) | 70% | ±1% | New code in pull requests |
| ampel-api | 75% | ±2% | API server routes and handlers |
| ampel-core | 85% | ±2% | Business logic (highest standard) |
| ampel-db | 80% | ±2% | Database queries and migrations |
| ampel-providers | 75% | ±2% | Git provider integrations |
| ampel-worker | 70% | ±2% | Background job processing |
| frontend | 75% | ±2% | React components and UI logic |
Coverage is automatically:
- Collected on every PR via GitHub Actions
- Reported to Codecov with backend/frontend flags
- Commented on PRs showing coverage changes
- Blocked if coverage drops below thresholds
Pull request coverage comments show:
- 🟢 Green (≥80%): Excellent coverage, target met
- 🟡 Yellow (60-79%): Acceptable coverage, could improve
- 🔴 Red (<60%): Needs improvement, add more tests
# 1. Make code changes
vim crates/ampel-core/src/lib.rs
# 2. Write tests
vim crates/ampel-core/tests/integration_tests.rs
# 3. Run tests with coverage
make test-backend-coverage
# 4. Check HTML report
open coverage/html/index.html
# 5. Improve coverage until green (≥80%)
# Add more tests...
# 6. Commit and push - CI will verify coverage
git add . && git commit -m "Add feature with tests"
git push- Create new
TestDbfor each test - Use real database queries (not mocks) for integration tests
- Use fixture builders for consistent test data
- Test both success and error cases
- Test behavior, not implementation details
- Use accessible queries (
getByRole,getByLabelText) - Mock external dependencies (API calls)
- Test user interactions with
userEvent
Last Updated: 2025-12-21