# 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 Docker/Podman : ```bash podman run --rm \ -v $(pwd):/workspace:Z \ -v /run/user/$(id -u)/podman/podman.sock:/var/run/docker.sock \ -w /workspace \ eclipse-temurin:25-jdk \ ./gradlew test --no-daemon ``` ## JaCoCo dans build.gradle ```groovy test { useJUnitPlatform() finalizedBy jacocoTestReport } jacocoTestReport { reports { xml.required = true } dependsOn test } jacocoTestCoverageVerification { violationRules { rule { limit { minimum = 0.90 } } } } ```