liveBook · Manning

Test automation framework

As explained in Code Like a Pro in Rust

A testing framework is a software framework that provides reusable structure and support for defining, executing, and reporting tests.

A test automation framework supplies reusable structure for defining, executing, and reporting tests. Rust includes a built-in unit testing framework that catches regressions and checks requirements before shipping, but it leaves several conveniences to libraries or custom code. section 6.0

Extend Rust’s built-in framework according to the testing problem:

  • Use parameterized or test-case for basic parameterized tests. section 6.3
  • Use rstest when tests need fixtures, or assert2 for Catch2-inspired assertions. section 6.3
  • Use proptest for generated inputs, automatic result checking, and minimized failing cases; retain hand-picked values for known specifications. section 6.3
  • Tune randomized test counts because property testing can consume additional CPU and cannot practically cover every value in large domains. section 6.3
Listing 6.3 Code listing of adder with proptest
pub fn add<T: std::ops::Add<Output = T>>(a: T, b: T) -> T {
    a + b
}
 
#[cfg(test)]
mod tests {
    use super::*;
    use proptest::prelude::*;                 #1
    proptest! {
        #[test]
        fn test_add(a: i64, b: i64) {         #2
            assert_eq!(add(a, b), a + b);     #3
        }
    }
}

The proptest listing shows a generic Rust function, generated i64 inputs, and an assertion that exposes arithmetic overflow. section 6.3

Finding and correcting overflow

A property test for generic addition can fail with a minimized pair of i64 values that overflows. Changing the implementation to use WrappingAdd and asserting against wrapping_add makes the intended behavior explicit; cargo test then passes. section 6.3

How Code Like a Pro in Rust covers it

How deep it goes
Explains built-in omissions, names extension libraries, and demonstrates property-testing failures without covering custom harness implementation.
Examples
Uses Rust’s built-in tests, parameterized crates, rstest fixtures, assert2 assertions, and proptest-based generic addition.
What it assumes
Assumes Rust testing familiarity while introducing the framework’s missing helpers and available ecosystem alternatives.
What you can do after
Diagnose arithmetic edge cases with proptest and select libraries for parameterization, fixtures, or specialized assertions.
How it connects
Connects unit testing with parameterized testing, fixtures, assertions, property testing, regression detection, and code refactoring.

Also explained in

Compare how 4 books explain test automation framework →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Code Like a Pro in Rust. The section links point to the parts of the book it draws on.