# Testing Requirements ## Coverage Threshold - **Minimum: 80% line coverage** for all backend code - Critical paths (auth, banning, scheduling, API endpoints): **100%** ## CI Enforcement `.github/workflows/ci.yml` runs pytest with `--cov-fail-under=80`. Build fails if coverage drops below threshold. ## Running Tests Locally ```bash cd backend pytest --cov=app --cov-report=term-missing ``` ## Coverage Reports - Terminal: `--cov-report=term-missing` - HTML: `--cov-report=html` (output in `htmlcov/`) ## Coverage Badge Add to README once CI runs successfully: ```md [![Coverage](https://codecov.io/gh//BanGUI/branch/main/graph/badge.svg)](https://codecov.io/gh//BanGUI) ``` Requires codecov.io integration with repository. ## Writing Tests - Follow pattern: `test___` - Mock external dependencies (fail2ban socket, aiohttp calls) - Test happy path AND error/edge cases - See `Docs/Backend-Development.md ยง9` for detailed testing guide ## E2E Testing An end-to-end test suite using **Robot Framework** with the Browser library (Playwright-backed) exercises the full running stack: frontend โ†’ backend โ†’ fail2ban โ†’ database. ### Running E2E Tests ```bash make e2e ``` Requires: - `BANGUI_SESSION_SECRET` env var must be set (see [Backend-Development.md](Backend-Development.md) for setup) - Stack must be startable via `make up` (Docker/Podman + compose installed) - `rfbrowser init` is run automatically by the `e2e` target (Playwright browsers downloaded on first run; re-run after `robotframework-browser` version changes) ### HTML Report After a run, open `e2e/results/report.html` in a browser to view the detailed HTML report with screenshots on failure. ### Writing New E2E Tests Place new `.robot` files in `e2e/tests/`. Use `e2e/resources/common.resource` for shared variables and setup/teardown, and `e2e/resources/auth.resource` for the `Login As Admin` keyword.