Skip to main content

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​

  1. Resource management: Monitor memory and CPU usage during tests
  2. Timeout handling: Set appropriate timeouts for test conditions
  3. Parallel execution: Run independent tests concurrently
  4. Cleanup: Ensure proper resource cleanup after tests

Best Practices​

Test Design​

  1. Isolation: Ensure tests don't depend on external state
  2. Deterministic: Tests should produce consistent results
  3. Fast: Unit tests should execute quickly
  4. Clear: Test names should clearly describe what is being tested

Debugging Unit Tests​

  1. Enable logging: Use detailed logging for test debugging
  2. Check assumptions: Ensure test assumptions match actual behavior
  3. Reproduce locally: Run failing tests locally for easier debugging
  4. 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