mirror of
https://github.com/furyhawk/lta_datamall_api.git
synced 2026-07-21 10:16:52 +00:00
2.1 KiB
2.1 KiB
name, description
| name | description |
|---|---|
| backend-testing | Use when adding, fixing, or reviewing backend tests for this FastAPI project, including route tests, service tests, cache behavior, and upstream error handling. |
Backend Testing Skill
Use this skill to design and implement robust tests for the backend API.
Project Context
- App framework: FastAPI
- Python environment: uv
- API routes: app/api/routes/bus.py
- Upstream client: app/services/lta_client.py
- Cache layer: app/services/cache.py
- App wiring and lifespan: app/main.py
Testing Goals
- Verify endpoint behavior, input validation, and response shape.
- Verify upstream failures are mapped to expected HTTP errors.
- Verify cache-assisted behavior does not break correctness.
- Keep tests deterministic with no real external API calls.
Workflow
- Identify the change surface and affected endpoints or services.
- Add or update tests under a test layout that mirrors app modules.
- Mock external dependencies:
- Mock DataMall calls from app/services/lta_client.py.
- Stub cache interactions from app/services/cache.py.
- Cover at least these scenarios per endpoint:
- Success response
- Input validation failure
- Upstream failure mapping
- Run checks and tests with uv.
- Keep tests readable with clear arrange, act, assert sections.
Preferred Patterns
- Use pytest-style tests and fixtures.
- Use FastAPI test clients for route-level coverage.
- Keep one behavior assertion focus per test.
- Use explicit test data, not random values.
- Name tests with behavior intent, for example: test_bus_arrival_returns_upstream_payload.
Commands
- Sync dependencies: make sync
- Compile check: make compile
- Run tests: uv run pytest
If pytest is not installed yet, add it to project dependencies before creating tests.
Quality Gate Before Finish
- New or changed behavior has corresponding tests.
- Tests do not call live DataMall services.
- Error handling and validation paths are covered.
- Existing compile check still passes.