Project Quality · 16 min · free with an account

Integration Tests

Lesson preview · about 30%

Test the public API as an outside user.

Core idea

Files under tests/ compile as separate crates and can only use the library's public API.

Start with the idea

Files under tests/ compile as separate crates and can only use the library's public API. That boundary catches accidental reliance on private implementation details.

An integration test behaves like an external user of your library. Each file under tests/ is compiled as a separate crate and imports the public API by crate name. It cannot reach private helpers simply because they exist in the same repository. That constraint is valuable: if a test can accomplish a real task through the public interface, downstream callers probably can too.

The sample test imports demo::answer and asserts a stable result. Add a second test for a boundary case and a third for an error path.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Cargo & Real Projects