Unit Tests
Overview
Basic unit tests for individual components provide the foundation of the testing infrastructure. These tests focus on testing individual functions, modules, and components in isolation.
Running Unit Tests
Standard Unit Tests
Run all unit tests across the codebase:
# Run all unit tests
make test
# Run tests in release mode
make test-release
# Use cargo-nextest for faster execution
make nextest
Performance Considerations
- Resource management: Monitor memory and CPU usage during tests
- Timeout handling: Set appropriate timeouts for test conditions
- Parallel execution: Run independent tests concurrently
- Cleanup: Ensure proper resource cleanup after tests
Best Practices
Test Design
- Isolation: Ensure tests don't depend on external state
- Deterministic: Tests should produce consistent results
- Fast: Unit tests should execute quickly
- Clear: Test names should clearly describe what is being tested
Debugging Unit Tests
- Enable logging: Use detailed logging for test debugging
- Check assumptions: Ensure test assumptions match actual behavior
- Reproduce locally: Run failing tests locally for easier debugging
- Update expectations: Adjust test expectations if behavior changed
Integration with CI
Unit tests run automatically in CI with:
- Container isolation: Each test runs in clean container
- Parallel execution: Multiple tests run concurrently
- Artifact collection: Test results archived for analysis
Related Documentation
- Testing Framework Overview: Main testing documentation
- Scenario Tests: Integration testing scenarios
- Getting Started: Basic development setup including testing