Fixtura โ€“ declarative test data injection for Rust. Pin only what your test depends on, fake the rest

โš“ Rust    ๐Ÿ“… 2026-05-10    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 1      

surdeus

fixtura 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:

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::Dummy on your types โ€” either derive it or impl manually.

Links

Happy to answer questions. Feedback on the API or missing features welcome.

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed