Errors
Most of what proptastic prints is a failure: an input that breaks your property. This page is the rest: a property that can’t run as written, or a run that stops because what it found would make a pass worthless. Each is something to fix in the test, not the code under test, and each says what to do.
The proptastic command’s own errors, each with a code and an exit status, are on Command errors.
A seed that isn’t hex
Section titled “A seed that isn’t hex”A seed is 0x and hex digits, as a failure prints it. A plain number could be read either way,
so it’s refused, with 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)Domains
Section titled “Domains”Bounds the wrong way round
Section titled “Bounds the wrong way round”@Testvoid aQuantityIsPositive() { var lots = integers().atLeast(10).atMost(1); forAll(lots).check(lot -> assertThat(lot).isPositive());}proptastic: integers().atLeast(10).atMost(1) has no values, because 10 is above 1.Swap the bounds, or drop one: integers().atLeast(1).atMost(10)A regular expression that can’t be drawn
Section titled “A regular expression that can’t be drawn”matching(…) draws strings a regular expression matches. A part that matches without drawing a
character, a lookahead, a back reference, a word boundary, can’t be drawn, so it’s refused, named:
@Testvoid aCodeIsNotAWord() { forAll(strings().matching("(?!word)[a-z]{4}")) .check(code -> assertThat(code).isNotEqualTo("word"));}matching() can't draw a lookaround or a flag, (?!w, at 2 in (?!word)[a-z]{4}A type any(…) can’t draw
Section titled “A type any(…) can’t draw”any(…) draws records, enums, sealed types and the types proptastic knows. Anything else, it
says so, and how to draw it yourself:
@Testvoid anythingAtAll() { forAll(any(Object.class)).check(thing -> assertThat(thing).isNotNull());}no domain for java.lang.Object: a record, an enum, a sealed type or a Kotlin data class can be drawn by type; for another, combine one with domain(…, constructor) or domain(source -> …)Runs that stop
Section titled “Runs that stop”A health check
Section titled “A health check”A filter or an assume(…) that rejects most of what’s drawn, or inputs too large, fails a run on
its first draws.
Health checks has each:
aRoundLotIsAWholeNumberOfHundreds failed a health check (seed 0x5eed) filter: filters rejected 1,628 of the 1,728 values they drew in the first 100 tries, over 3 in 4 rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'HealthTest.aRoundLotIsAWholeNumberOfHundreds' ! build values that meet the filter, in place of discarding the rest ! or say why it's fine: .allow("filter", "…")A case that’s too rare
Section titled “A case that’s too rare”A require(…) that surely came up less often than it asks fails the run, with no counterexample:
fullBasketsComeUp covered too little in 800 tries (seed 0x5eed) too rare: "twenty items or more" in 57 of 800 tries (7.12%), needs 20% rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'RequireTest.fullBasketsComeUp' ! draw it more often: weighted(…), .edges(…), averageSize(…) or a domain of its own or check one input you know every run: .example(…), in place of require
classify tries twenty items or more 57 7.1% █▍
sizes p50 p90 p99 basket 5 17 31Classify and require says how sure it has to be. A share the
tries can’t tell either way, even at 64 times the tries, is incomplete: the property passes and
says so, passed, but its coverage is incomplete after 6,400 tries, unless
PROPTASTIC_INCOMPLETE=fail, when it fails with the same facts and the classify table.
An outcome that never came up
Section titled “An outcome that never came up”When a property follows a model and one of the model’s outcomes never came up, the run fails, as it checked nothing of that case:
model Calendar.isLeap's outcome century (a multiple of 100, not of 400) never came up in 1,000 tries (seed 0x5eed), so following it said nothing of that case: widen the domains, or say why it can't with .unreachable("century", "…") rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'LeapYearTest.thisCenturyByRule'Follow a model has .unreachable(…), for an outcome that can’t.
Settings on a property
Section titled “Settings on a property”Every value of too many
Section titled “Every value of too many”aFeeIsNeverMoreThanALotForAnyCount: .exhaustively() runs every value, but its draws have more than 100,000: bound them, or draw them at randomEvery value has the rest.
A health check that doesn’t exist
Section titled “A health check that doesn’t exist”@Testvoid aListIsAllowedToBeLong() { forAll(lists(integers())) .allow("size", "long lists are the point") .check(xs -> assertThat(xs).hasSizeGreaterThanOrEqualTo(0));}allow() names a health check, one of [filter, large, slow], not sizeToo many threads
Section titled “Too many threads”@Testvoid manyHandsOnOneList() { var adds = steps(ArrayList<Integer>::new).step("add", list -> list.add(1)); forAll(adds).threads(16).check();}.threads(n) takes 1 to 8 threads: 16Each thread multiplies the schedules to search, so a few threads find most races: two, or three.