Skip to main content

Factory

Derive Macro Factory 

Source
#[derive(Factory)]
Expand description

Derive a test factory for an entity.

ⓘ
#[derive(Entity, Clone, Default, Factory)]
struct User { id: u64, email: String }

let users = User::factory().count(3).make();

Generates User::factory(), building each row from [Default] — so the type needs one, and three rows are three identical rows until a .sequence(..) distinguishes them. Anything with a UNIQUE column therefore needs one; see the trait’s own documentation for why that is not automatic.

The expansion is deliberately tiny. A derive that invented plausible values per field would have to guess what each column means, and a wrong guess produces a row that fails to insert for a reason nobody can see from the test that wrote it.