Seeds and replay
A failure you can’t run again is a failure you can’t fix. proptastic’s runs are random, so each run checks inputs the last one didn’t, but every random choice comes from a seed, and the seed makes any run repeatable.
A seed decides every input
Section titled “A seed decides every input”Every random try in a run comes from one seed. Unless you set one, each run picks a new seed, so each run checks different inputs. The seed, the test method’s name and its parameter types decide every value: the same seed draws the same inputs, run after run, on any machine. The class isn’t part of it, so a copy of the test in another class draws the same inputs too.
Set a seed with .seed(0x5eed) on the property, or for a whole run with PROPTASTIC_SEED; the
property’s own wins. Seeds are written 0x and hex digits, as a failure prints them. A seed
written as a plain number is refused, since 12345 and 0x12345 are different seeds and it
can’t tell which you meant. The message names where the seed came from, PROPTASTIC_SEED or, as
here, the system property, and gives both readings:
proptastic: the system property proptastic.seed is 12345, which isn't a seed. Seeds are 0x and hex digits, as failures print them. PROPTASTIC_SEED=0x12345 ./gradlew test --tests 'SeedsTest.aDecimalSeed' (or 0x3039, if 12345 was decimal)The order a run checks inputs in
Section titled “The order a run checks inputs in”- The examples pinned with
.example(…), every time, in order. - The counterexample the last run saved, if there is one, so a bug you’re fixing is checked first, before anything random.
- The property’s corpus entries, if it has any: inputs kept from earlier counterexamples.
- The random tries, 100 unless
.tries(…),PROPTASTIC_TRIESor the profile says otherwise.
How a run works has the rest of a run around these.
A failure is kept, and replayed
Section titled “A failure is kept, and replayed”When a property fails, proptastic saves its counterexample’s choices in
build/proptastic/counterexamples/ (target/proptastic/ under Maven), a file named for the
test. The next run tries that input before anything else. While it still fails, the header says
failed on its saved counterexample, so a bug you’re working on fails at once, every run, with
no seed to copy. Once it passes, the file is deleted.
PROPTASTIC_REPLAY=false turns this off: nothing is saved or replayed. To keep an input for
good, past this one fix, pin it with .example(…).
The saved input is its choices, so it still replays after you change the code, or the domain.
The rerun line
Section titled “The rerun line”A failure ends with a line that runs that one test again with its seed. It’s written in the command your build runs tests with:
PROPTASTIC_SEED=0x4f1c2a9e7b3d5f60 ./gradlew test \ --tests 'BankAccountTest.aTransferWithAFeeKeepsTheTotal'or ./mvnw test -Dtest=… under Maven. When the proptastic command runs your build,
it sets PROPTASTIC_COMMANDS=proptastic, and the line is the command’s own, which works the same
on any build:
Expecting actual: 1000to be less than: 1000
aBasketCostsUnderAThousand failed after 4 tries (seed 0x5eed) shrunk counterexample: basket = Basket[500, 500] pin it: .seed(0x5eed) // no source form for this input rerun: proptastic run --only='concepts.PinsTest#aBasketCostsUnderAThousand()' --seed=0x5eedThe command’s own Next: line, after a failure, is that rerun, and running it runs the property
alone, its saved counterexample first:
proptastic run --only='SortTest#sortKeepsSize()' --seed=0x2fc03457e2e24c2 Failed ────────────────────────────────────────────────────────────────
✗ SortTest#sortKeepsSize counterexample ca97c5d54 expected: <2> but was: <1>
sortKeepsSize failed on its saved counterexample (seed 0x2fc03457e2e24c2) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: proptastic run --only='SortTest#sortKeepsSize()' --seed=0x2fc03457e2e24c2
Next: proptastic run --only='SortTest#sortKeepsSize()' --seed=0x2fc03457e2e24c2
Properties ✗ 1 failed (1) Ran ./gradlew test --rerun --tests SortTest.sortKeepsSize Reports build/proptastic/report/report.json · build/proptastic/report/index.html