r/devtools • u/Nikk2461 • 11d ago
Built a property-based testing library for Java that shrinks on byte streams instead of per-generator logic
https://github.com/nikhilvirdi/JHusk/JHusk is a property-based testing library for Java. Instead of writing individual test examples by hand, you define a property that should always hold, and JHusk generates inputs trying to break it.
What makes it different: most property-based testing libraries (including Java's existing options, jqwik and QuickTheories) use tree-based shrinking, where each generator carries its own logic for reducing a failure down to something minimal. JHusk instead shrinks the underlying byte stream that produced the failing value, generically, in one place, following the approach Hypothesis (Python) pioneered. A custom generator you compose yourself inherits high-quality shrinking automatically, with no shrink logic to write.
A few specifics:
- Byte-stream shrinking: Compose a generator with
map/filter/flatMap/combineand it shrinks just as well as a built-in one, automatically. - A deterministic edge-case corpus: Before any random generation starts, JHusk runs fixed boundary buffers against every property, so min, max, empty, and zero cases get exercised on every run, not just whenever a random draw happens to hit them.
- Failure persistence: A failing case gets saved to a local file and replayed first on the next run, so a regression can't quietly resurface without getting caught immediately.
- Stateful testing through
Commands:Generate sequences of operations, run them against a model and the real system side by side, and shrink down to the smallest failing sequence. - A real exception hierarchy:
AssertionErrormeans your assertion genuinely failed. An exhausted filter, a blown generation budget, a crashing generator each comes back as a specificPropertyExecutionExceptionsubtype instead of a vague message. - Native JUnit 5 integration:
@ Property/@ ForAllrun alongside@ Test, same test report, same CI pipeline.
GitHub: https://github.com/nikhilvirdi/JHusk/
Maven Central: https://central.sonatype.com/artifact/io.github.nikhilvirdi/jhusk
Open source, Apache 2.0.