Files
docs/standards_src/wiki/10_testing.md

57 lines
1.7 KiB
Markdown

# Testing
## Summary
Two test suites: **integration** (the HTTP edge with fakes) and **unit** (pure
domain and pipeline logic). Both run under pytest with asyncio auto mode.
---
## Layout
```
tests/
integration/ # TestClient(app) + mocked resources
unit/ # models, converters, pipeline stages/roots
conftest.py # fixtures
```
## Integration tests
- Build the app with `TestClient`.
- Replace `app.state.resources` with fake repositories/services so no database
is required.
- Patch the auth introspection call (`httpx.AsyncClient.post`) to return a
canned identity.
- Assert status codes and bodies for list/get/create/update/delete, plus
`400`, `404`, `204`, and the streaming endpoint's fallback.
```python
client = TestClient(app)
app.state.resources = {"item_svc": FakeItemService(), ...}
def test_create_item():
r = client.post("/items", json={"name": "x"})
assert r.status_code == 200
```
## Unit tests
- Domain models and converters: pure, no I/O.
- Pipeline stages: feed a fixture state, assert the transformed state.
- Assembled pipeline roots: **fixture parity** — replay a stored fixture input
and compare against a golden output file.
## Config-consistency tests
For rule-driven pipelines, add a test that cross-references rules against the
declared pattern registry: every flag emitted must be defined; every defined
flag must be reachable. This catches drift without running the pipeline.
## Conventions
- `asyncio_mode = "auto"`; no manual event loops.
- Fixtures are checked into the repo (inputs + golden outputs).
- Tests skip (not fail) when a required fixture is absent.
- Do not mock the domain; mock only the infrastructure edge.