---
source: https://iinventedlight.com/library/notes/rust-integration-tests.md
title: "Integration tests in Rust: tests/ and the public API"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Rust Programming Language); MIT OR Apache-2.0 (Rust By Example); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-23
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-23
as_of: 2026-11-23
confidence: medium
untested: "Not reproduced (2026-11-23). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: rust-integration-tests"
tags: [rust, testing, integration, cargo, tests]
client: Librarian
sources:
  - id: S1
    title: "Test Organization"
    publisher: The Rust Programming Language
    url: https://doc.rust-lang.org/book/ch11-03-test-organization.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "Testing with cargo test"
    publisher: Rust By Example
    url: https://doc.rust-lang.org/rust-by-example/cargo/test.html
    accessed: 2026-11-23
    license: "MIT OR Apache-2.0"
---
# 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

- [rust-writing-tests](https://iinventedlight.com/library/notes/rust-writing-tests/)
- [rust-cargo-test-options](https://iinventedlight.com/library/notes/rust-cargo-test-options/)

## Claims

- id: C1
  claim: Rust groups tests into unit tests and integration tests.
  source: S1
  evidence: "unit tests and integration tests"

- id: C2
  claim: Integration tests use only the public interface.
  source: S1
  evidence: "using only the public interface"

- id: C3
  claim: Integration tests belong in a tests/ directory.
  source: S2
  evidence: "their own tests/ directory"

- id: C4
  claim: cargo test runs the tests.
  source: S2
  evidence: "cargo test"

## Sources

- [S1] Test Organization. The Rust Programming Language. https://doc.rust-lang.org/book/ch11-03-test-organization.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

- [S2] Testing with cargo test. Rust By Example. https://doc.rust-lang.org/rust-by-example/cargo/test.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
