This document outlines all the different ways you can test the Reactive Trading Simulator project.
| Testing Approach | Purpose | Tools |
|---|---|---|
| Unit Testing | Test individual components in isolation | Alcotest |
| Property-Based Testing | Test invariants across random inputs | QCheck2, QCheck-Alcotest |
| Integration Testing | Test component interactions | Alcotest |
| Stress Testing | Test performance under load | Custom + Alcotest |
| Scenario Testing | Test realistic market scenarios | Custom + Alcotest |
| Benchmark Testing | Measure and compare performance | Core_bench |
Ensure you have all required dependencies:
opam install alcotest qcheck qcheck-alcotest core_benchTo run the complete test suite:
dune runtestTo run only specific test files:
dune test test/test_order_book.ml
dune test test/test_agents.mlUnit tests verify that individual components work correctly in isolation. Our project has unit tests for:
- Order Book operations (
test_order_book.ml) - Agent strategies (
test_agents.ml)
Property-based tests verify invariants that should hold across many different inputs:
- No crossed book after matching operations
- Empty book properties
- Trade quantity validation
Integration tests verify that components work together correctly:
- Agent interaction with order book
- Simulation step correctness
- End-to-end trading scenarios
See: Integration Testing Guide
Stress tests verify that the system performs well under high load:
- High volume order processing
- Deep order book matching
- Performance under extreme conditions
See: Stress Testing Guide
Scenario tests verify the system's behavior in realistic market conditions:
- Flash crash recovery
- Price momentum
- Market volatility
Benchmark tests measure the performance of critical operations:
- Order insertion throughput
- Order matching speed
- Book operation efficiency
- Start with unit tests: Ensure core components work correctly before testing interactions
- Add property tests: Define invariants that should always hold
- Create integration tests: Verify component interactions
- Add scenario tests: Test realistic market conditions
- Benchmark critical paths: Identify and optimize performance bottlenecks
When adding new functionality, follow this testing workflow:
- Write unit tests for the new component
- Define properties that should hold for the component
- Update integration tests to include the new component
- Add relevant scenario tests
- Benchmark if performance-critical
OCaml's type system can catch many errors, but can sometimes be confusing. Common issues:
- Confusion between
orderandtradetypes - Missing type annotations
- Record field access type mismatches
When tests fail, look for:
- Incorrect expectations
- Edge cases not handled
- Random seed issues in property tests (use the seed to reproduce)
For continuous integration, you can run:
dune runtestThis will execute all tests and return a non-zero exit code if any tests fail.