Testing strategy and philosophy for Sentinel development.
Testing Philosophy
Test Pyramid
/\
/ \ E2E Tests (few)
/----\ Integration Tests (some)
/------\ Unit Tests (many)
/--------\
- Unit tests: Fast, isolated, test individual functions
- Integration tests: Test component interactions
- E2E tests: Full system tests with real connections
What to Test
| Component | Test Type | Focus |
|---|---|---|
| Config parsing | Unit | Valid/invalid inputs |
| Route matching | Unit | Path patterns, priorities |
| Health checks | Integration | HTTP/TCP checks |
| Agent protocol | Integration | Message encoding/decoding |
| Full proxy | E2E | Request/response flow |
Running Tests
All Tests
# Run all tests
# With output
# Release mode (faster, but slower to compile)
Specific Tests
# Single test
# Tests matching pattern
# Tests in module
# Single package in workspace
Test Options
# Show test output even for passing tests
# Run ignored tests
# Run tests in parallel (default)
# Run tests sequentially
Using cargo-nextest
Faster test runner with better output:
# Install
# Run tests
# With retries for flaky tests
# Filter by test name
Test Organization
Unit Tests
In the same file as the code:
// src/routing/matcher.rs
Integration Tests
In tests/ directory:
// tests/proxy_test.rs
use TestServer;
async
Test Utilities
Create shared test helpers:
// src/test_utils.rs (or tests/common/mod.rs)
Async Testing
tokio::test
async
// With custom runtime
async
Timeouts
use ;
async
Testing Cancellation
async
Mocking
Trait-Based Mocking
// Define trait
// Production implementation
;
// Test mock
mockall Crate
use ;
Fixtures and Test Data
Test Fixtures
// tests/fixtures/mod.rs
Temporary Files
use ;
Property-Based Testing
use *;
proptest!
Coverage
Using cargo-tarpaulin
# Install
# Generate report
# Exclude test code
# Only specific packages
Using cargo-llvm-cov
# Install
# Generate report
# Open report
CI Testing
GitHub Actions
name: Tests
on:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Run tests
run: cargo test --all-features
- name: Run clippy
run: cargo clippy -- -D warnings
- name: Check formatting
run: cargo fmt --check
Next Steps
- Unit Tests - Detailed unit testing guide
- Integration Tests - E2E testing
- Load Testing - Performance testing