Prototype for property-based testing #712
Replies: 4 comments 7 replies
-
jqwik 2 will have an API independent from JUnit. You may want to participate in the discussion about a good API on https://github.com/jqwik-team/jqwik2-api-discussion |
Beta Was this translation helpful? Give feedback.
-
We'd love property-based testing in Pkl! CC @holzensp, who's bought it up many times in our convos. Looking at your example: how does it work? For example, how does the test runner know to supply values of Do you have a commit with this pushed up anywhere? Would love to take a look. Also, maybe silly question (my knowledge is limited here): have you considered hand-rolling PBT? Do we need to depend on a library for this? |
Beta Was this translation helpful? Give feedback.
-
It analyzes the Truffle AST for
It's quite a large change set, and I might have to clean it up first. :-)
I did for a moment, but implementing high-quality generators and shrinkers isn't easy. |
Beta Was this translation helpful? Give feedback.
-
I had just come across Wholly agreed with a lot (if not all) of @translatenix's remarks here (hand rolling PBT should not be undertaken lightly, JUnit dependencies are heavy, analyse-time-unknown things translate to discards). |
Beta Was this translation helpful? Give feedback.
-
Some time ago, I implemented a fairly complete prototype for property-based testing in Pkl. Here is a small (and artificial) example:
mytest.pkl
Running
pkl test mytest.pkl
produces the following output:Generation of property inputs is entirely driven by test parameter types
such as
String(length == 99)
andPerson(firstName.isWithinCharRange("a", "f"))
. (String.isWithinCharRange
is one of several predicates I added to the stdlib.) Values of almost all Pkl types can be generated, including almost all stdlib types.Many constraints, including those used in the above example, are understood and used to inform input generation. Constraints that aren't understood are used to discard generated inputs. If more than
settings.properties.maxDiscardRatio
inputs are discarded, the test fails.When a property is falsified, inputs are shrunk to find a small counterexample. In the above example, shrinking produced the smallest possible counterexample
Set("")
. Shrinking is essential for a good user experience.Why I stopped working towards a PR
Input generation and shrinking is delegated to jqwik, a Java library for property-based testing. Unfortunately, jqwik is heavily tied to JUnit. While jqwik can also be used as a plain Java library, its public API is quite limited (no shrinking), and JUnit is still required at runtime.
To overcome these limitations, I had to make substantial changes to jqwik's source code. Eventually I concluded that modifying jqwik's source code is a showstopper, even just to get my PR through a code review.
As far as I know, jqwik is the only actively maintained property-based testing library for Java. jqwik 2.0 plans to offer a standalone library that supports shrinking and doesn't depend on JUnit. However, due to a lack of funding, its development has stalled.
kotest-property looks promising but is implemented in Kotlin, which seems to rule out its use in a Pkl stdlib module.
Beta Was this translation helpful? Give feedback.
All reactions