An integration test exercises a component through its public interface, as another component or user would. In Rust, integration tests live outside the main source tree and compile as separate crates, so they cannot call private helpers. Use them alongside unit tests, which can check those helpers directly. section 7.1
A practical Rust workflow:
- Put a test file in the top-level `tests/` directory. Import the crate’s public API, mark test functions with `#[test]`, and check results with assertions. Cargo discovers and runs the tests. section 7.1
- Write cases that reflect how someone actually uses the API. A passing result checks behavior; awkward test setup can also reveal an interface that needs redesign. section 7.2
- Keep focused unit tests for internal behavior. Do not duplicate their private-helper checks through an integration harness. section 7.1 section 7.2
Listing 7.2 Code sample of the integration test for quicksort implementation
use quicksort::quicksort;
#[test]
fn test_quicksort() {
let mut values = vec![12, 1, 5, 0, 6, 2];
quicksort(&mut values);
assert_eq!(values, vec![0, 1, 2, 5, 6, 12]);
let mut values = vec![1, 13, 5, 10, 6, 2, 0];
quicksort(&mut values);
assert_eq!(values, vec![0, 1, 2, 5, 6, 10, 13]);
}
A `tests/`-style test imports the public `quicksort` function, supplies two input vectors, and asserts the sorted outputs. section 7.1
Choose the harness to match the boundary. Rust’s built-in tests are sufficient for many cases and need no tooling beyond the Rust toolchain. For an HTTP service, curl or HTTPie may be simpler; a CLI may be easier to test with a Bash, Ruby, or Python script. Weigh that convenience against the portability of an all-Rust test suite. section 7.3 section 7.6
Property-based tests can broaden coverage: use `proptest` to generate inputs and compare results against an expected behavior. If generated cases write to a database or make network requests, restore a known state before and after tests so side effects do not contaminate later runs. Executable rustdoc examples offer another public-facing check: `cargo test` compiles and runs their code and assertions. section 7.4.2 section 2.8.1






























