Testing strategy¶
This page outlines the testing approach across the PetFolio platform, covering the testing pyramid, test types, and integration test infrastructure.
Testing pyramid¶
Tests are organised in a pyramid structure with more unit tests than integration tests:
graph TD
A[Integration Tests] --> B[Application Unit Tests]
B --> C[Domain Unit Tests]
classDef layer-api fill:#4a90d926,stroke:#4a90d9,stroke-width:2px
classDef layer-domain fill:#7ed32126,stroke:#7ed321,stroke-width:2px
classDef layer-infra fill:#f5a6232e,stroke:#f5a623,stroke-width:2px
class A layer-api
class B layer-domain
class C layer-infra
Diagram key
- Blue (API layer): Integration tests - full API-to-database flow, fewest in number
- Green (Domain): Application unit tests - handlers and validators with mocked dependencies
- Orange (Infrastructure): Domain unit tests - pure domain logic, most numerous and fastest
Test Characteristics:
| Test Type | Speed | Quantity | Dependencies | Purpose |
|---|---|---|---|---|
| Domain Unit Tests | Fastest | Most | None (pure domain) | Test value objects and entities |
| Application Unit Tests | Fast | Medium | Mocked repositories | Test handlers and validators |
| Integration Tests | Slower | Fewest | Real database (Docker) | Test full API → Database flow |
BE¶
Integration test setup¶
- Uses Testcontainers for real MySQL database in Docker
- All tests share a single container for performance (marked with
[Collection(nameof(IntegrationTestCollection))]) - Each test gets a clean database automatically
- Inherits from
BaseIntegrationTestfor common setup