With your test framework
You already have a test framework, and you don’t want a second one. proptastic isn’t one.
forAll(…).check(…) is a call you make inside a test you already write. When the check fails,
it throws an AssertionError, and your framework reports it like any other failed assertion. So
the setup is one dependency, and the test is the one you’d write anyway.
What changes from one framework to the next is how the failure is framed: what the test is called, and where proptastic’s report sits in what the build tool prints. This page shows that for each framework, so you know what to look for.
Each example checks the same sort, which has a bug: it puts the list through a set, so repeated
values are lost. Every one of them finds it, and shrinks the list to [0, 0]. Each example is a
real build, run under Gradle and Maven, and each output is what that run printed, with
PROPTASTIC_SEED=0x5eed.
The examples get proptastic from Maven Central, as your build will
(Install). just frameworks, in a clone of proptastic, runs each one
against the jar built from that clone instead, installed in a repository of the clone’s own,
build/frameworks-maven, so your own local repository is left as it was. The versions below are those the examples run with.
JUnit 5
Section titled “JUnit 5”JUnit Jupiter, on the JUnit Platform. Most of these docs use it.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins { java}
dependencies { testImplementation("io.proptastic:proptastic:1.0.0") testImplementation(platform("org.junit:junit-bom:5.12.2")) testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher")}
tasks.test { useJUnitPlatform() testLogging { exceptionFormat = TestExceptionFormat.FULL showStackTraces = false }}<dependency> <groupId>io.proptastic</groupId> <artifactId>proptastic</artifactId> <version>1.0.0</version> <scope>test</scope></dependency><dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.12.2</version> <scope>test</scope></dependency>import static io.proptastic.Proptastic.forAll;import static io.proptastic.Proptastic.integers;import static io.proptastic.Proptastic.lists;import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;import java.util.List;import java.util.TreeSet;import org.junit.jupiter.api.Test;
class SortTest { @Test void sortKeepsSize() { var ints = lists(integers()); forAll(ints).check(xs -> assertEquals(xs.size(), sort(xs).size())); }
/** A sort with a bug: a set drops repeated values. */ static List<Integer> sort(List<Integer> xs) { return new ArrayList<>(new TreeSet<>(xs)); }}SortTest > sortKeepsSize() FAILED io.proptastic.core.PropertyFailure: expected: <2> but was: <1>
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'SortTest.sortKeepsSize'
Caused by: org.opentest4j.AssertionFailedError: expected: <2> but was: <1>[ERROR] Failures:[ERROR] SortTest.sortKeepsSize:16 expected: <2> but was: <1>
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./mvnw test -Dtest='SortTest#sortKeepsSize'Gradle names the test SortTest > sortKeepsSize(). The exception is proptastic’s
PropertyFailure, and its message starts with your assertion’s own, then the report. Your
assertion’s error is its cause, and it keeps the expected and actual values, so an IDE can still
show them side by side. Maven’s summary names the test and the line, and its rerun line uses
./mvnw and -Dtest.
JUnit 4
Section titled “JUnit 4”On JUnit 4’s own runner: Gradle’s useJUnit(), and Surefire’s JUnit 4 provider, which it picks
when it finds JUnit 4.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins { java}
dependencies { testImplementation("io.proptastic:proptastic:1.0.0") testImplementation("junit:junit:4.13.2")}
tasks.test { useJUnit() testLogging { exceptionFormat = TestExceptionFormat.FULL showStackTraces = false }}<dependency> <groupId>io.proptastic</groupId> <artifactId>proptastic</artifactId> <version>1.0.0</version> <scope>test</scope></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope></dependency>import static io.proptastic.Proptastic.forAll;import static io.proptastic.Proptastic.integers;import static io.proptastic.Proptastic.lists;import static org.junit.Assert.assertEquals;
import java.util.ArrayList;import java.util.List;import java.util.TreeSet;import org.junit.Test;
public class SortTest { @Test public void sortKeepsSize() { var ints = lists(integers()); forAll(ints).check(xs -> assertEquals(xs.size(), sort(xs).size())); }
/** A sort with a bug: a set drops repeated values. */ static List<Integer> sort(List<Integer> xs) { return new ArrayList<>(new TreeSet<>(xs)); }}SortTest > sortKeepsSize FAILED io.proptastic.core.PropertyFailure: expected:<2> but was:<1>
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'SortTest.sortKeepsSize'
Caused by: java.lang.AssertionError: expected:<2> but was:<1>[ERROR] Failures:[ERROR] SortTest.sortKeepsSize:16 expected:<2> but was:<1>
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./mvnw test -Dtest='SortTest#sortKeepsSize'It reads as JUnit 5’s does, with JUnit 4’s wording for the assertion: expected:<2> but was:<1>.
JUnit 4 has no parentheses after the test’s name.
TestNG
Section titled “TestNG”On TestNG’s own runner: Gradle’s useTestNG(), and Surefire’s TestNG provider.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins { java}
dependencies { testImplementation("io.proptastic:proptastic:1.0.0") testImplementation("org.testng:testng:7.11.0")}
tasks.test { useTestNG() testLogging { exceptionFormat = TestExceptionFormat.FULL showStackTraces = false }}<dependency> <groupId>io.proptastic</groupId> <artifactId>proptastic</artifactId> <version>1.0.0</version> <scope>test</scope></dependency><dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.11.0</version> <scope>test</scope></dependency>import static io.proptastic.Proptastic.forAll;import static io.proptastic.Proptastic.integers;import static io.proptastic.Proptastic.lists;import static org.testng.Assert.assertEquals;
import java.util.ArrayList;import java.util.List;import java.util.TreeSet;import org.testng.annotations.Test;
public class SortTest { @Test public void sortKeepsSize() { var ints = lists(integers()); forAll(ints).check(xs -> assertEquals(sort(xs).size(), xs.size())); }
/** A sort with a bug: a set drops repeated values. */ static List<Integer> sort(List<Integer> xs) { return new ArrayList<>(new TreeSet<>(xs)); }}Gradle suite > Gradle test > SortTest > sortKeepsSize FAILED io.proptastic.core.PropertyFailure: expected [2] but found [1]
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'SortTest.sortKeepsSize'
Caused by: java.lang.AssertionError: expected [2] but found [1][ERROR] Failures:[ERROR] SortTest.sortKeepsSize:16 expected [2] but found [1]
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./mvnw test -Dtest='SortTest#sortKeepsSize'TestNG’s assertEquals takes the actual value first, then the expected one. Gradle puts its own
suite names in front of the test’s: Gradle suite > Gradle test > SortTest > sortKeepsSize.
Kotlin, with JUnit 5
Section titled “Kotlin, with JUnit 5”Kotlin calls proptastic as Java does. A Kotlin lambda is the check, and its parameter’s name is the one the failure prints.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins { kotlin("jvm") version "2.2.21"}
dependencies { testImplementation("io.proptastic:proptastic:1.0.0") testImplementation(platform("org.junit:junit-bom:5.12.2")) testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher")}
tasks.test { useJUnitPlatform() testLogging { exceptionFormat = TestExceptionFormat.FULL showStackTraces = false }}<dependency> <groupId>io.proptastic</groupId> <artifactId>proptastic</artifactId> <version>1.0.0</version> <scope>test</scope></dependency><dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.12.2</version> <scope>test</scope></dependency>import io.proptastic.Proptastic.forAllimport io.proptastic.Proptastic.integersimport io.proptastic.Proptastic.listsimport org.junit.jupiter.api.Assertions.assertEqualsimport org.junit.jupiter.api.Test
class SortTest { @Test fun sortKeepsSize() { forAll(lists(integers())).check { xs -> assertEquals(xs.size, sort(xs).size) } }}
/** A sort with a bug: a set drops repeated values. */fun sort(xs: List<Int>): List<Int> = xs.toSortedSet().toList()SortTest > sortKeepsSize() FAILED io.proptastic.core.PropertyFailure: expected: <2> but was: <1>
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'SortTest.sortKeepsSize'
Caused by: org.opentest4j.AssertionFailedError: expected: <2> but was: <1>[ERROR] Failures:[ERROR] SortTest.sortKeepsSize:12 expected: <2> but was: <1>
sortKeepsSize failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./mvnw test -Dtest='SortTest#sortKeepsSize'Kotest
Section titled “Kotest”Kotest runs on the JUnit Platform. A Kotest test’s name isn’t on the stack, so proptastic names the property by its spec’s file and line, and reruns the whole spec.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins { kotlin("jvm") version "2.2.21"}
dependencies { testImplementation("io.proptastic:proptastic:1.0.0") testImplementation("io.kotest:kotest-runner-junit5:5.9.1")}
tasks.test { useJUnitPlatform() testLogging { exceptionFormat = TestExceptionFormat.FULL showStackTraces = false }}<dependency> <groupId>io.proptastic</groupId> <artifactId>proptastic</artifactId> <version>1.0.0</version> <scope>test</scope></dependency><dependency> <groupId>io.kotest</groupId> <artifactId>kotest-runner-junit5-jvm</artifactId> <version>5.9.1</version> <scope>test</scope></dependency>Surefire runs only classes named for tests, such as SortTest, so tell it to run specs too:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.5.4</version> <configuration> <includes> <include>**/*Spec.*</include> </includes> </configuration></plugin>import io.kotest.core.spec.style.StringSpecimport io.kotest.matchers.shouldBeimport io.proptastic.Proptastic.forAllimport io.proptastic.Proptastic.integersimport io.proptastic.Proptastic.lists
class SortSpec : StringSpec({ "sort keeps the size" { forAll(lists(integers())).check { xs -> sort(xs).size shouldBe xs.size } } })
/** A sort with a bug: a set drops repeated values. */fun sort(xs: List<Int>): List<Int> = xs.toSortedSet().toList()SortSpec > sort keeps the size FAILED io.proptastic.core.PropertyFailure: expected:<2> but was:<1>
SortSpec.kt:11 failed after 2 tries (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'SortSpec'
Caused by: io.kotest.assertions.AssertionFailedError: expected:<2> but was:<1>[ERROR] Failures:[ERROR] SortSpec expected:<2> but was:<1>
SortSpec.kt:11 failed after 2 tries (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./mvnw test -Dtest='SortSpec'Gradle names the test by Kotest’s own name, sort keeps the size. The report calls it
SortSpec.kt:11, where the check is, and its rerun line runs SortSpec, every test in the spec,
with the seed that found the counterexample.
Spock runs on the JUnit Platform too. The report names the property for the feature, as the spec does, and its rerun line runs that feature.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins { groovy}
dependencies { testImplementation("io.proptastic:proptastic:1.0.0") testImplementation("org.spockframework:spock-core:2.3-groovy-4.0") testImplementation("org.apache.groovy:groovy:4.0.28") testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.12.2")}
tasks.test { useJUnitPlatform() testLogging { exceptionFormat = TestExceptionFormat.FULL showStackTraces = false }}<dependency> <groupId>io.proptastic</groupId> <artifactId>proptastic</artifactId> <version>1.0.0</version> <scope>test</scope></dependency><dependency> <groupId>org.spockframework</groupId> <artifactId>spock-core</artifactId> <version>2.3-groovy-4.0</version> <scope>test</scope></dependency><dependency> <groupId>org.apache.groovy</groupId> <artifactId>groovy</artifactId> <version>4.0.28</version> <scope>test</scope></dependency>Surefire runs only classes named for tests, such as SortTest, so tell it to run specs too:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.5.4</version> <configuration> <includes> <include>**/*Spec.*</include> </includes> </configuration></plugin>import static io.proptastic.Proptastic.forAllimport static io.proptastic.Proptastic.integersimport static io.proptastic.Proptastic.lists
import spock.lang.Specification
class SortSpec extends Specification { def "sort keeps the size"() { setup: forAll(lists(integers())).check { xs -> assert sort(xs).size() == xs.size() } }
/** A sort with a bug: a set drops repeated values. */ static List<Integer> sort(List<Integer> xs) { new ArrayList<>(new TreeSet<>(xs)) }}SortSpec > sort keeps the size FAILED io.proptastic.core.PropertyFailure: Condition not satisfied:
sort(xs).size() == xs.size() | | | | | | [0] | 1 | | 2 [0, 0] | [0, 0] false
sort keeps the size failed after 2 tries (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'SortSpec.sort keeps the size'
Caused by: Condition not satisfied:
sort(xs).size() == xs.size() | | | | | | [0] | 1 | | 2 [0, 0] | [0, 0] false[ERROR] Failures:[ERROR] SortSpec.sort keeps the size:12 Condition not satisfied:
sort(xs).size() == xs.size()| | | | | |[0] | 1 | | 2 [0, 0] | [0, 0] false
sort keeps the size failed after 2 tries (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0)) rerun: PROPTASTIC_SEED=0x5eed ./mvnw test -Dtest='SortSpec#sort keeps the size'The check is a setup: block, not expect:. In expect:, Spock treats the call as a condition,
and prints the whole failure, stack trace and all, inside its own report. Groovy’s assert shows
each part of the condition, then proptastic’s report follows, with the closure’s parameter name:
xs = [0, 0].
A plain main
Section titled “A plain main”No test framework at all: check throws, and the exception ends the program. That suits a quick
experiment, or a check run from a script.
plugins { application}
dependencies { implementation("io.proptastic:proptastic:1.0.0")}
application { mainClass = "SortCheck"}<dependency> <groupId>io.proptastic</groupId> <artifactId>proptastic</artifactId> <version>1.0.0</version></dependency>To run it, add the exec plugin:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>3.5.1</version> <configuration> <mainClass>SortCheck</mainClass> </configuration></plugin>import static io.proptastic.Proptastic.forAll;import static io.proptastic.Proptastic.integers;import static io.proptastic.Proptastic.lists;
import java.util.ArrayList;import java.util.List;import java.util.TreeSet;
public class SortCheck { public static void main(String[] args) { forAll(lists(integers())) .check( xs -> { if (sort(xs).size() != xs.size()) { throw new AssertionError("sorted " + xs + " into " + sort(xs)); } }); }
/** A sort with a bug: a set drops repeated values. */ static List<Integer> sort(List<Integer> xs) { return new ArrayList<>(new TreeSet<>(xs)); }}Exception in thread "main" io.proptastic.core.PropertyFailure: sorted [0, 0] into [0]
main (SortCheck.java:13) failed after 1 try (seed 0x5eed) shrunk counterexample: xs = [0, 0] pin it: .example(List.of(0, 0))[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.5.1:java (default-cli) on project main: An exception occurred while executing the Java class. sorted [0, 0] into [0][ERROR][ERROR] main (SortCheck.java:13) failed after 1 try (seed 0x5eed)[ERROR] shrunk counterexample: xs = [0, 0][ERROR] pin it: .example(List.of(0, 0))Your own AssertionError gives the first line. The report names the property for the method and
the line, main (SortCheck.java:13), so two checks in one main are told apart. It has no rerun
line: proptastic prints one only when a Gradle or Maven test run is running it. Rerun with the seed
from the header.
In colour
Section titled “In colour”A failure is read in a hurry: which test, what input, what to paste. Colour makes those findable at a glance, where it’s rendered. But the same text also lands in files and panes that show colour as noise, and a reader who doesn’t see colour must lose nothing. So proptastic only ever adds colour to what it prints plain, and only where it knows colour will be rendered:
- On the test’s own terminal, such as a plain main run from a shell.
- In IntelliJ IDEA’s own JUnit runner, whose test pane renders it. A run IntelliJ hands to Gradle is Gradle’s, below.
- Anywhere
FORCE_COLORis set, the convention for asking for colour where it can’t be detected.
It never colours with NO_COLOR set or TERM=dumb, nor for a coding agent (PROPTASTIC_AGENT) or
mutastic, which read the plain text.
Gradle and Maven run your tests in a process of their own and pipe what it prints to their
console, so the test can’t see the terminal. They also write the same text into their XML and HTML
test reports, where colour shows as ?[1;31m. So they get plain text unless you ask:
PROPTASTIC_COLOR=always colours their console, and their reports with it. never turns colour
off everywhere. Both are on the settings page.
The colours are mutastic’s, so the two read as one family. Red is only on the word that says something failed; the input is bold; cyan is what you copy (the seed, the pin line, the rerun command, a model’s version); labels are dim; green is what passed and amber a warning. On threads, the columns’ headings and the locks’ names are bold, and what a step did with a lock is dim. These are the failures and passes from the other pages, as a terminal shows them:
expected: <50> but was: <51>
aTransferWithAFeeKeepsTheTotal failed after 2 tries (seed 0x4f1c2a9e7b3d5f60) shrunk counterexample: aliceHas = 50, bobHas = 0, amount = 50 fails for any: bobHas pin it: .example(/* aliceHas */ 50L, /* bobHas */ 0L, /* amount */ 50L) rerun: PROPTASTIC_SEED=0x4f1c2a9e7b3d5f60 ./gradlew test --tests 'BankAccountTest.aTransferWithAFeeKeepsTheTotal'invariant "money is conserved" broke after step 3: withdraw("alice", 1)
theBankKeepsItsBooks failed after 9 tries (seed 0x1) shrunk steps: 1. deposit("bob", 1) 2. transfer("bob", "alice", 1) 3. withdraw("alice", 1) ← bob = 0, alice = 1 pin it: .example( step("deposit", "bob", 1L), step("transfer", "bob", "alice", 1L), step("withdraw", "alice", 1L)) // typed pins come from @StepBuilder rerun: PROPTASTIC_SEED=0x1 ./gradlew test --tests 'StatefulBankTest.theBankKeepsItsBooks'does not follow model Desk.canExecute (Java)model Desk.canExecute said true, code said false (outcome fits)
theDeskFollowsTheModel failed after 2 tries (seed 0x5eed) shrunk counterexample: order = new Order(0, 1, 1) // Order(held, quantity, limit) pin it: .example(new Order(0L, 1L, 1L)) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'DeskFollowsTheModelTest.theDeskFollowsTheModel'does not follow spec Reserve 1 (TLA+)step 2 is not one spec Reserve allows: reserve("B") allowed position = 80, reserved = 15, status = {A=approved, B=rejected, C=new} did position = 80, reserved = 30, status = {A=approved, B=approved, C=new} differs reserved 15 → 30 · status[B] rejected → approved keeps invariants Within, Accounted
aCheckThenExecuteDeskDoesnt failed after 3 tries (seed 0x5eed) shrunk steps: 1. reserve("A") 2. reserve("B") ← position 80, reserved 30, {A=APPROVED, B=APPROVED} pin it: .example(reserve("A"), reserve("B")) // import static spec.ReserveStep.* rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'DeskFollowsTheSpecTest.aCheckThenExecuteDeskDoesnt'deadlock: thread 1 holds "London", waits for "NewYork"; thread 2 holds "NewYork", waits for "London"
theInheritedDeskNeverDeadlocks failed after 1 try (seed 0x2) shrunk steps: thread 1 thread 2 1. move("London", "NewYork", 1) locks "London" paused before it takes "NewYork" 1. move("NewYork", "London", 1) locks "NewYork" waits for "London" waits for "NewYork" pin it: .example( thread(move("London", "NewYork", 1L)), thread(move("NewYork", "London", 1L))) // import static deadlock.BookingStep.* rerun: PROPTASTIC_SEED=0x2 ./gradlew test --tests 'MovesAtOnceTest.theInheritedDeskNeverDeadlocks'followed model Desk.canExecute on 100 tries (Java) · outcomes fits 100 · breach unreachable (these orders are all far below the limit) how sure: 0 of 100 tries failed, so under 3% of inputs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/passed on 2 threads, 100 runs (every schedule with up to 2 preemptions: 5,724) · no deadlock · held "no book passes its limit" · each fits an order of its steps, one at a time how sure: 0 of 100 runs failed, so under 3% of runs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/Strip the colour and each is the plain text proptastic prints elsewhere, character for character: the build checks it.
Not yet
Section titled “Not yet”These work, but with gaps that proptastic has still to fix:
- Kotest: the whole spec. A Kotest test’s name isn’t on the stack, so the rerun line runs every test in its spec, not the one that failed.
- Spock:
expect:. A check in anexpect:block is printed inside Spock’s condition report, with its stack trace. Usesetup:. - A plain main: no rerun line. There’s no test run to name, so rerun with the seed from the header.