Expand description
The structured test toolkit. A sync Rust library for named cases, optional lifecycle
hooks, and cargo test integration
via run—without a custom harness or DSL.
§How a run works
- You build a static slice of
Casevalues withcases!and passHookFnsplusRunConfigtorun. runselects which cases to execute: either all of them, or only the one whoseCase::nameequalsRunConfig::filter.- If nothing is selected and a filter was set, it panics (likely a typo). If nothing is selected and there is no filter, it returns immediately (empty case list).
- Otherwise it runs optional hooks in order:
setup_suite→ for each selected case:before_each→ case body →after_each→ thenteardown_suite. Hook slots that areNoneinHookFnsare skipped.
Panics inside a case are caught so after_each still runs; the panic is re-raised afterward.
§Macros
| Macro | Role |
|---|---|
cases! | Build &'static [Case<S>] from inline blocks per case |
test_suite! | Emit one #[test] per case; all share one Mutex suite (optional inline cases! syntax so names are not repeated) |
§Assertions
The assert module provides testify-style
helpers (equal, no_error, contains, …) that panic on failure, for use in tests and
suite case bodies.
§Mocking
The mock module provides testify/mock-style
expectations and call recording (mock::Mock, [mock::mock_args!]).
§Example
use suitecase::{cases, run, Case, HookFns, RunConfig};
#[derive(Default)]
struct Counter {
n: i32,
}
static CASES: &[Case<Counter>] = cases![Counter, s =>
test_inc => { s.n += 1; },
];
let mut suite = Counter::default();
run(&mut suite, CASES, RunConfig::all(), &HookFns::default());
assert_eq!(suite.n, 1);Re-exports§
Modules§
- assert
- Panicking assertion helpers for tests (in the spirit of Go’s testify/assert).
- mock
- Test doubles with expectations and call recording, in the spirit of Go’s testify/mock.
- suite
- Suite runner:
Caselists,HookFns,RunConfig, andrun.
Macros§
- cases
- Build a
&'static [Case<S>]from case names and inline blocks. - mock_
args - Builds
Argumentsfrom a list of expressions, each boxed asAny+Send. - test_
suite - Emit one
#[test]per listed case name. Each test locks a shared suite behind astd::sync::Mutexin astd::sync::OnceLockkeyed by$storage, then callsrunwithRunConfig::filterand yourHookFns.