VelocityGate enforces a high standard of code quality through a multi-layered testing strategy, aiming for >80% code coverage and robust integration verification.
We adhere to the classic testing pyramid:
- Unit Tests (70%): Fast, isolated tests for individual classes (Rate Limiters, Utilities, Services).
- Integration Tests (20%): Verifies interaction between components and external infrastructure (Redis, Postgres) using Testcontainers.
- E2E / Load Tests (10%): Validates system behavior under realistic traffic (k6, Chaos).
- Algorithms: Verify token bucket refill math, sliding window precision, and edge cases (e.g., negative tokens).
- Security: JWT signature validation, expiration handling, and API key hashing vectors.
- Resilience: Circuit breaker state transitions (CLOSED -> OPEN -> HALF-OPEN).
- JUnit 5: Test runner.
- Mockito: Mocking external dependencies (Repositories, RedisTemplate).
- Project Reactor Test:
StepVerifierfor reactive stream assertions.
We do not mock databases in integration tests. We use Testcontainers to spin up ephemeral Docker instances of Redis and PostgreSQL.
- Distributed Rate Limiting: Spin up 2 Gateway instances (embedded) sharing one Redis container to verify lock contention and quota synchronization.
- Data Persistence: Verify API keys and User data survive restarts.
- Failure Recovery: Kill the Redis container mid-test and verify "Fail-Open" behavior.
We use JaCoCo to enforce coverage metrics. The build fails if limits are not met.
| Metric | Threshold |
|---|---|
| Line Coverage | 80% |
| Branch Coverage | 70% |
| Missed Classes | 0 |
Exclusions: DTOs, Configuration classes, and Generated code (Lombok).
- SpotBugs: Scans for common bugs (NullPointer dereferences, resource leaks).
- Checkstyle: Enforces Google Java Style (indentation, naming conventions).
- SonarQube: Continuous inspection of code quality (optional integration).
mvn clean verifymvn testmvn jacoco:report
# View at target/site/jacoco/index.html