Fixtura โ declarative test data injection for Rust. Pin only what your test depends on, fake the rest
โ Rust ๐ 2026-05-10 ๐ค surdeus ๐๏ธ 1fixtura lets you declare exactly what each test parameter depends on and fakes
everything else automatically. Built on fake-rs.
How it works
Add #[cfg_attr(test, derive(fake::Dummy))] to your struct, then declare test
parameters with only the fields that matter:
#[fixtura::test]
fn inactive_users_cannot_checkout(
#[fixtura(active = false)] user: User,
order: Order,
) {
assert!(checkout(&user, &order).is_err());
}
Only active is pinned because only active drives the logic. Everything
else โ IDs, names, timestamps โ is faked automatically.
Cross-argument references work too:
#[fixtura::test]
fn order_belongs_to_user(
user: User,
#[fixtura(user_id = user.id)] order: Order,
) {
assert_eq!(order.user_id, user.id);
}
Real-world result
I migrated CILens, a CI analytics tool I built, to fixtura:
- 5
create_test_*helpers deleted - Test suite shrank by 25%
- ~120 struct fields that were hardcoded for no reason now freely faked
The before/after is in the PRs if you want to see what an actual migration
looks like:
- feat: migrate test suite to fixtura by dsalaza4 ยท Pull Request #12 ยท dsalaza4/cilens ยท GitHub โ initial migration
- test(core): unpin fields not needed by test assertions by dsalaza4 ยท Pull Request #13 ยท dsalaza4/cilens ยท GitHub โ removing unnecessary pins
Limitations I'm honest about
- Tuple structs: field overrides aren't supported by position, only by name.
Workaround: use a named struct or wrap the tuple struct. - Async tests: works fine, but the attribute ordering matters (
#[fixtura::test]
must come before async runtime attributes like#[tokio::test]). - Requires
fake::Dummyon your types โ either derive it or impl manually.
Links
- crates.io: crates.io: Rust Package Registry
- GitHub: GitHub - dsalaza4/fixtura: Declarative fake data injection for Rust tests, built on fake-rs. ยท GitHub
- MSRV: 1.85 (Rust 2024 edition)
Happy to answer questions. Feedback on the API or missing features welcome.
1 post - 1 participant
๐ท๏ธ Rust_feed