Create a tests directory at your project root and write functions annotated with #[test] that import and verify your library's public API.
Write integration tests by placing test files in a tests directory at the root of your project, where each file is a separate crate that imports your library.
// File: tests/integration_test.rs
use my_library::add;
#[test]
fn test_add() {
assert_eq!(add(2, 2), 4);
}
Run these tests with cargo test.
Integration tests verify that different parts of your software work together correctly, unlike unit tests which check individual pieces in isolation. Think of unit tests as checking if a car engine runs, while integration tests check if the whole car drives down the road. You write these in a separate tests folder so they can import your library just like an external user would.