Skip to main content
Version: v1.2.x

Reproducible generation

By default Fixture Monkey generates different values on every run. When a randomly generated fixture reveals a bug, you'll want to reproduce it deterministically. Set a fixed seed on the builder to make generation reproducible.

Fixing the seed on the builder

FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.seed(12345L)
.build();

With a fixed seed, the same builder produces the same values — and, as of v1.2.0, the same container sizes — across runs.

Reproducing a single test with @Seed

When using the JUnit 5 extension, annotate a test with @Seed to pin its seed. If the test fails, the extension logs the seed that produced the failure so you can reproduce it later.

@Seed(12345L)
@Test
void reproducibleTest() {
// always generates the same values
}
info

As of v1.2.0, an active @Seed takes precedence over FixtureMonkeyBuilder#seed(long): while a @Seed (or FixtureMonkeySeedExtension) is active, the builder's own seed is ignored. The seed is scoped to the test and released afterwards — even if the test or another extension throws — so it no longer leaks into later tests.