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 Strategy

Testing during migration serves a dual purpose: verifying that the Rust code is correct on its own, and confirming that it preserves the behavior of the original. Batuta enforces a layered testing strategy aligned with the Certeza quality methodology.

Testing Pyramid

              /\
             /  \        Tier 4: CI/CD
            / E2E\       Release tests, mutation, pmat analysis
           /──────\
          / Integ  \     Tier 3: Pre-push
         / ration   \    Full test suite, cross-module
        /────────────\
       /   Unit       \  Tier 2: Pre-commit
      /   Tests        \ cargo test --lib, clippy
     /──────────────────\
    /  Static Analysis   \ Tier 1: On-save
   / fmt, clippy, check   \ < 1 second
  /────────────────────────\

Quality Tiers

TierTriggerTime BudgetWhat Runs
Tier 1On save< 1scargo fmt, cargo clippy, cargo check
Tier 2Pre-commit< 5scargo test --lib, complexity gate
Tier 3Pre-push1-5 minFull tests, integration tests
Tier 4CI/CD5-30 minRelease tests, mutation testing, pmat analysis

Run tiers via Make:

make tier1   # On-save checks
make tier2   # Pre-commit gate
make tier3   # Pre-push validation
make tier4   # Full CI/CD pipeline

Coverage Requirements

The Sovereign AI Stack enforces strict coverage targets:

  • 90% minimum (enforced, build fails below this)
  • 95% preferred (target for all new code)
make coverage   # Generates HTML + LCOV in target/coverage/

Migration-Specific Testing

During migration, every transpiled module needs three test categories:

  1. Parity tests: Output matches original implementation for the same input
  2. Property tests: Invariants hold across random inputs (proptest)
  3. Regression tests: Previously-fixed bugs stay fixed
#![allow(unused)]
fn main() {
#[test]
fn parity_with_python_output() {
    // Known input/output pairs captured from Python
    let input = vec![1.0, 2.0, 3.0];
    let expected = vec![2.0, 4.0, 6.0];
    assert_eq!(transform(&input), expected);
}
}

Test Organization

src/
  module.rs           # Production code
  module/
    tests.rs          # Unit tests (use super::*)
tests/
  integration/
    module_test.rs    # Integration tests
  parity/
    module_parity.rs  # Python output comparison

See the following chapters for detailed guidance on Test Migration, Property-Based Testing, and Regression Prevention.


Navigate: Table of Contents