Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing

Running Tests

# Full workspace
cargo test --workspace

# Specific crate
cargo test --package acls-rs
cargo test --package hbac-rs
cargo test --package abac-rs
cargo test --package perf-testing

# With output visible
cargo test -- --nocapture

# Single test by name
cargo test --package hbac-rs deny_rule

Test Organization

acls-rs

Unit tests for algebraic permission operations, subject construction, role hierarchy resolution, ABAC evaluation, and temporal permission validity. Tests live in #[cfg(test)] modules alongside the implementation.

hbac-rs

Unit tests for rule construction, category semantics, request matching, policy evaluation (allow/deny precedence, dimension matching), and the optimization pipeline (Bloom filter, decision tree, deny-rule index).

Integration tests under tests/ cover end-to-end evaluation scenarios: multi-rule policies, temporal rules, composed policies, and cache pipeline behavior.

With the jit feature enabled, additional tests cover rule classification, Cranelift compilation, and JIT runtime evaluation:

cargo test --package hbac-rs --features jit

abac-rs

Unit tests for rule construction, attribute matching, policy evaluation (allow/deny precedence, multi-type attributes), compiled evaluator, and bitmap-based deny index.

Integration tests under tests/ cover end-to-end scenarios: multi-type attributes (String, Integer, Float, IpAddr, IpCidr), custom matchers, deny rules, and cache behavior.

perf-testing

Tests for fixture generation (distribution presets, reproducibility with seeded RNG), fixture I/O (compression, schema validation), and benchmark scenario execution.

Performance Benchmarks

Benchmarks are separate from the test suite. Use the bac-perf CLI:

# Generate a fixture and run all scenarios
cargo run --release --package perf-testing -- \
  generate --count 1000 --output test_1k --seed 42

cargo run --release --package perf-testing -- \
  bench --fixture test_1k --scenario all --cache

For statistically rigorous measurements with Criterion:

cd crates/perf-testing
cargo bench --bench hbac_benchmarks

See Performance Testing Framework for the full workflow.

Local CI

Run the complete CI pipeline before submitting changes:

./scripts/local-ci.sh all

This runs build, fmt, clippy, doc, test, bench-quick, and examples in sequence. Any failure stops the pipeline.

Writing Tests

  • Place unit tests in #[cfg(test)] modules next to the code they test
  • Place integration tests in tests/ directories within each crate
  • Use assert! / assert_eq! with descriptive messages for failures
  • Test both the happy path and error conditions (e.g., CategoryError when adding to a Category::All)
  • For HBAC evaluation tests, use evaluate_detailed() to inspect which rules matched