# Tests — Olhar-API ## Couverture minimale : 90% La couverture (lignes, branches, méthodes) doit être **≥ 90%** en permanence, vérifiée via JaCoCo. Le seuil global est défini dans les règles workspace (`tests.md`). ## Types de tests | Type | Outil | Suffixe de classe | |------|-------|-------------------| | Unitaire | JUnit 5 | `*Test` | | Intégration | JUnit 5 + Testcontainers + PostgreSQL | `*IT` | Les tests d'intégration étendent `AbstractIntegrationTest` qui démarre un conteneur PostgreSQL via Testcontainers. ## Structure attendue Pour chaque classe de production, une classe de test correspondante : - `JwtService` → `JwtServiceTest` (unitaire, pas de Spring context) - `AuthController` → `AuthControllerIT` (intégration, `@SpringBootTest`) - `UserRepositoryAdapter` → test d'intégration avec BDD réelle ## Exécution via Podman (obligatoire) Voir `java-env.md` (règles workspace) pour les contraintes. Commande standard : ```bash podman run --rm -v $(pwd):/workspace:Z -w /workspace eclipse-temurin:25-jdk ./gradlew test --no-daemon ``` Testcontainers nécessite le socket Podman et le réseau hôte (DinD) : ```bash podman run --rm \ --privileged \ --network host \ -v $(pwd):/workspace:Z \ -v /run/user/$(id -u)/podman/podman.sock:/var/run/docker.sock:Z \ -e DOCKER_HOST=unix:///var/run/docker.sock \ -e TESTCONTAINERS_RYUK_DISABLED=true \ -w /workspace \ eclipse-temurin:25-jdk \ ./gradlew test --no-daemon ``` - `--network host` est obligatoire : le TC JDBC driver démarre PostgreSQL via le socket Podman et s'y connecte via `localhost:PORT` — sans host network, ce port n'est pas accessible depuis l'intérieur du container. - `TESTCONTAINERS_RYUK_DISABLED=true` : Ryuk (le garbage collector de Testcontainers) ne fonctionne pas en DinD. ## JaCoCo dans build.gradle ```groovy test { useJUnitPlatform() finalizedBy jacocoTestReport } jacocoTestReport { reports { xml.required = true } dependsOn test } jacocoTestCoverageVerification { violationRules { rule { limit { minimum = 0.90 } } } } ```