Skip to content

Testing and Verification

tien.nguyen edited this page Jul 30, 2026 · 3 revisions

Testing & Verification Strategy

The Emporia Trading Platform employs a multi-layered verification strategy combining automated unit tests, integration tests with real databases, deterministic concurrency schedulers, and static code quality enforcement.


🧪 Verification Matrix

Layer Tools & Frameworks Target & Purpose Verification Command
Unit & Mock Testing JUnit 5, Mockito, AssertJ Individual business logic, records, state machines mvn test
Code Coverage JaCoCo (0.8.15) Enforcement of 91.95%+ instruction & branch coverage mvn verify
Database Concurrency Testcontainers, PostgreSQL Pessimistic vs Optimistic locking under parallel transactions mvn test -Dtest=*PostgresConcurrencySpec
Controlled Concurrency Fray Scheduler (0.9.0) Controlled JVM thread interleavings (200 iterations, 170 timelines) mvn -Pfray -pl order-management-service -am test
Static Code Quality PMD (7.26.0), Custom Ruleset Code correctness, resource management, exception handling mvn pmd:check

🔬 Multi-Layered Testing Details

1. JaCoCo Code Coverage Standard

  • Every microservice defines a strict JaCoCo enforcement profile requiring minimum 90% instruction and branch coverage.
  • Excludes auto-generated Protocol Buffers / gRPC classes and FIX protocol models.
# Run test suite with JaCoCo coverage reports across all 9 modules
mvn clean verify

2. Database Concurrency Testing (Testcontainers)

  • Specification: TradingOrderPostgresConcurrencySpec in order-management-service.
  • Purpose: Spawns ephemeral PostgreSQL instances via Testcontainers to verify JPA @Version optimistic locking and SQL pessimistic write locks under heavy concurrent transaction load.

3. Fray Deterministic Thread Scheduling

  • Specification: TradingOrderFraySpec in order-management-service.
  • Purpose: Uses Fray's byte-code instrumentation to explore 200 distinct thread interleavings between simultaneous applyFill and cancel executions on shared TradingOrder entities.
# Run Fray controlled thread scheduling specification
mvn -Pfray -pl order-management-service -am test

4. PMD Static Analysis Enforcement

  • Ruleset: static-analysis/ruleset.xml.
  • Enforces:
    • Proper exception catching (no swallowed exceptions).
    • Explicit resource cleanup (try-with-resources).
    • Clean concurrency primitives.
    • Zero violation tolerance (pmd.failOnViolation=true).
# Run PMD static code check
mvn pmd:check -Dpmd.failOnViolation=true

Clone this wiki locally