Suitcase
The library package name is suitcase — use suitcase = "0.1" in Cargo.toml (or path / git as below).
The structured test toolkit. A lightweight sync Rust library for named cases, optional setup / teardown at suite scope and before_each / after_each around each case, plus macros so every case can show up as its own line in cargo test—without a custom harness or DSL. Filter to a single case when you want isolation; hooks still run in the right order.
Heavy development: The API is still evolving. Expect breaking changes between releases until a stable 1.0; pin an exact version (or git revision) in Cargo.toml if you need upgrades to be predictable.
Install · Usage · Examples · Docs (after publish; cargo doc --open locally)
- Sync runner —
runorchestrates hooks and case bodies; integrate async I/O with something liketokio::runtime::Handle::block_onin hooks or cases. - Hooks as optional fns —
HookFnsholdsOption<fn(&mut S)>per lifecycle slot; use [None] to skip. - Named cases — build
&'static [Case<S>]withsuite_methods!,cases!, orcases_fn!. - One line per case in
cargo test—cargo_case_tests!/cargo_case_tests_with_hooks!emit a#[test]per case name (each run usesRunConfig::filter).
Install
Add suitcase to your Cargo.toml (no required dependencies beyond std):
[]
= "0.1"
Usage
Quickstart
Put this in tests/suite.rs (integration test) or inside #[cfg(test)] mod tests { ... } in your crate:
use ;
static CASES: & = suite_methods!;
Run: cargo test
Hooks
Pass HookFns as the last argument to run. Each field is Option<fn(&mut S)> — wrap your function in [Some(...)] or use [None] / [HookFns::default()] to skip.
use ;
static CASES: & = suite_methods!;
static HOOKS: = HookFns ;
Run: cargo test
Run a single case (filter)
use ;
static CASES: & = suite_methods!;
Run: cargo test
Show each case in cargo test
Rust lists one line per #[test]. To list each case separately, use cargo_case_tests! (default hooks) or cargo_case_tests_with_hooks! at the root of an integration test file (tests/*.rs):
use ;
// static MY_CASES: &[Case<MySuite>] = suite_methods![MySuite, s => test_a, test_b];
// static MY_HOOKS: HookFns<MySuite> = HookFns { /* ... */ };
cargo_case_tests_with_hooks!;
Run: cargo test — you should see one test per listed case name.
Each case body should be correct when it is the only case selected (fresh suite state unless you seed in the body).
Examples
| Example | Run |
|---|---|
examples/sqlx_sqlite.rs |
cargo run --example sqlx_sqlite |
Integration tests in this repo (tests/) |
cargo test |
That example uses sqlx + tokio, applies embedded migrations in setup_suite, and runs several free-function cases with cases_fn! and HookFns. Enable the same stack in your crate if you copy the pattern:
[]
= "0.1"
= { = "0.8", = ["runtime-tokio", "sqlite", "migrate"] }
= { = "1", = ["macros", "rt-multi-thread"] }
See tests/suite.rs and tests/sqlx_sqlite.rs for full implementations of these patterns.