Unit Tests¶
Unit tests verify a single function or class in isolation — without a database, network, or browser. They are the base of the test pyramid: the most numerous, the fastest, the most precise in their error messages.
What this level verifies¶
- Backend business logic: pure calculations and engine rules (VPD via Tetens, GDD accumulation, EC budget), adapter logic (GBIF/Perenual enrichment).
- Frontend logic without a DOM: Redux slices (reducers, actions) and custom hooks that are testable as pure functions.
Tested areas at a glance¶
| Area | Tested elements | Extent |
|---|---|---|
| Domain logic (backend) | VPD/GDD/EC calculations, phase engine, karenz gate, companion/crop rotation | extensive |
| Repositories (backend) | ArangoDB access, graph queries | extensive |
| Migrations | schema migration framework | extensive |
| Celery tasks | background jobs, retention/anonymization | moderate |
| Adapters | weather (DWD/Open-Meteo/OWM/NASA), GBIF, Perenual, PlantNet, Home Assistant, notifications | moderate |
| Frontend | Redux slices, custom hooks | moderate |
Tooling & location¶
| Backend | Frontend | |
|---|---|---|
| Tooling | pytest (asyncio_mode = "auto") | vitest |
| Location | src/backend/tests/unit/ | src/frontend/src/test/store/, …/hooks/ |
| Dependencies | none external | none (no provider wrapper needed) |
Running¶
Full prerequisites and patterns are in the testing concept → Backend Tests and → Frontend Tests.
Conventions¶
- Engine tests instantiate the class directly and mock no repositories.
- Service tests mock the repository (
AsyncMock(spec=…)). - Redux slice tests run entirely without React — call the reducer as a pure function.
- Every new feature needs at least one unit test for its business logic.