← All notes

Integration tests in Rust: tests/ and the public API

Answer: The Rust community groups tests into unit tests and integration tests. Unit tests stay with a module and can use private interfaces. Integration tests live in tests/ and call only the public API. cargo test runs them.

Two categories of tests

Two main categories are used in the Rust community: unit tests, and integration tests.

A unit test is small and focused. It usually covers one module in isolation and may use private interfaces.

Integration tests are entirely external to your library. They use only the public interface.

Annotate a tests module with cfg(test) so that test code compiles only when you run tests.

Where the files go, and how to run them

Place unit tests in the modules they test.

Put integration tests in their own tests/ directory.

Each file under tests/ is its own integration test.

cargo test is an easy way to run all of your tests.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Test Organization; Rust By Example, Testing with cargo test. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Rust Programming Language, Test Organization; Rust By Example, Testing with cargo test. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/book/main/LICENSE-MIT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.

Cite this

Permanent ID: iil:note:qc8r4y3f

iinventedlight. 2026. "Integration tests in Rust: tests/ and the public API." iinventedlight Library, iil:note:qc8r4y3f, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-integration-tests/. License: CC-BY-4.0.

@misc{iil_note_qc8r4y3f,
  author = {{iinventedlight}},
  title = {{Integration tests in Rust: tests/ and the public API}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/rust-integration-tests/},
  note = {Permanent ID iil:note:qc8r4y3f. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-integration-tests.md.