Skip to content

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 Jupiter, on the JUnit Platform. Most of these docs use it.

build.gradle.kts
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
}
}
SortTest.java
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));
}
}
./gradlew test
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>

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.

On JUnit 4’s own runner: Gradle’s useJUnit(), and Surefire’s JUnit 4 provider, which it picks when it finds JUnit 4.

build.gradle.kts
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
}
}
SortTest.java
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));
}
}
./gradlew test
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>

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.

On TestNG’s own runner: Gradle’s useTestNG(), and Surefire’s TestNG provider.

build.gradle.kts
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
}
}
SortTest.java
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));
}
}
./gradlew test
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]

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 calls proptastic as Java does. A Kotlin lambda is the check, and its parameter’s name is the one the failure prints.

build.gradle.kts
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
}
}
SortTest.kt
import io.proptastic.Proptastic.forAll
import io.proptastic.Proptastic.integers
import io.proptastic.Proptastic.lists
import org.junit.jupiter.api.Assertions.assertEquals
import 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()
./gradlew test
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>

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.

build.gradle.kts
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
}
}
SortSpec.kt
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import io.proptastic.Proptastic.forAll
import io.proptastic.Proptastic.integers
import 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()
./gradlew test
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>

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.

build.gradle.kts
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
}
}
SortSpec.groovy
import static io.proptastic.Proptastic.forAll
import static io.proptastic.Proptastic.integers
import 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))
}
}
./gradlew test
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

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].

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.

build.gradle.kts
plugins {
application
}
dependencies {
implementation("io.proptastic:proptastic:1.0.0")
}
application {
mainClass = "SortCheck"
}
SortCheck.java
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));
}
}
./gradlew run
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))

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.

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_COLOR is 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:

Terminal window
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'

Strip the colour and each is the plain text proptastic prints elsewhere, character for character: the build checks it.

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 an expect: block is printed inside Spock’s condition report, with its stack trace. Use setup:.
  • A plain main: no rerun line. There’s no test run to name, so rerun with the seed from the header.

Privacy