# Testing Standards
## 1. Running Tests
```bash
cargo test --all-targets
```
## 2. Core Rules
1. **Deterministic & Offline Only:** Unit tests must never call live internet endpoints (Gemini, YouTube, Telegram, GitHub), real Bale/SMS APIs, or real `systemd` services.
2. **Trait Mocking:** Test `src/engine/` (failover, anti-flapping, auto-recovery, alert cooldowns) using in-memory mock implementations of `ProxyCore`, `HealthProbe`, and `Notifier`.
3. **Isolated Filesystem (`tempfile`):** Any test that reads or writes `config.yaml`, Xray `config.json`, or state files must use `tempfile::TempDir` and verify atomic write behavior.
4. **Reproduce Before Fixing:** Every bug fix must start with a failing test that reproduces the bug, followed by the fix making it pass.
5. **Valid & Invalid Inputs:** Configuration parsing and probe status classification tests must cover both valid inputs and malformed/edge-case inputs (timeouts, `403`/`429`, missing fields, duplicate profile names).
6. **Test-Only Panics:** `.unwrap()` and `.expect()` are permitted in `#[cfg(test)]` modules and `tests/` integration tests, never in runtime `src/` code.
7. **Always Update Tests with Code Changes:** Whenever a new feature is added or existing behavior is modified, add or update unit tests in the same change to cover all relevant cases (happy path, empty/boundary states, invalid inputs, and regression scenarios). Currently the project uses unit tests (`#[cfg(test)]`) only.