module-concept

Rust Integration tests and public API boundaries

Cargo builds an integration-test target as its own crate. It can exercise the library through its public API, like a downstream consumer. Unit tests nested inside a module can instead use private details available in that module’s scope. The lab tests a public calculation without reaching its helper. Multi-file fixture: integration-boundary. The code shown is one source file, not a standalone program. Expected result (not executed): Test target exits successfully (assertion passes; harness text varies). Why: The assertion checks the library’s public behavior. Common mistake: Trying to access internal_price from the integration-test crate.

Formal Syntax & Structure

rust syntaxrust
tests/public_api.rs

Working Example

Example Snippetrust
#[test]fn totals_match() { assert_eq!(catalog_demo::total(3), 15); }
Rust Reference