Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Property based testing for Java 8
| Date | Stars |
|---|---|
| 2026-07-24 | 517 |
| 2026-07-25 | 517 |
| 2026-07-28 | 517 |
| 2026-07-30 | 517 |
| 2026-08-06 | 517 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
[](https://dev.azure.com/henrycoles/quicktheories/_build/latest?definitionId=2&branchName=master)
[](https://maven-badges.herokuapp.com/maven-central/org.quicktheories/quicktheories)
# QuickTheories
Property-based testing for Java 8.
If you were looking for QuickCheck for Java you just found it.
Unlike many other systems QuickTheories supports both auto-magical shrinking and targeted search using coverage data.
## What is property based testing
Traditional unit testing is performed by specifying a series of concrete examples and asserting on the outputs/behaviour of the unit under test.
Property based testing moves away from concrete examples and instead checks that certain properties hold true for all possible inputs. It does this by automatically generating
a random sample of valid inputs from the possible values.
This can be a good way to uncover bad assumptions made by you and your code.
If the word "random" is making you feel a little nervous, don't worry QuickTheories provides ways to keep your tests repeatable.
## Quick Start
Add the QuickTheories jar to your build (see the badge at the top of the page for the maven coordinates of the latest version).
You can run QuickTheories from JUnit, TestNG or any other test framework.
Here we are using JUnit
```java
import static org.quicktheories.QuickTheory.qt;
import static org.quicktheories.generators.SourceDSL.*;
public class SomeTests {
@Test
public void addingTwoPositiveIntegersAlwaysGivesAPositiveInteger(){
qt()
.forAll(integers().allPositive()
, integers().allPositive())
.check((i,j) -> i + j > 0);
}
}
```
The static import `org.quicktheories.QuickTheory.qt` provides access to the QuickTheories DSL.
The static import `org.quicktheories.generators.SourceDSL.*` provides access to a DSL that allows valid inputs to be defined.
This property looks pretty simple, it just checks that adding two integers always produces a number greater than 0.
This couldn't possibly fail could it? That would mean math was broken.
If we run this test we get something like :-
```
java.lang.AssertionError: Property falsified after 1 example(s)
Smallest found falsifying value(s) :-
{840226137, 1309274625}
Other found falsifying value(s) :-
{848253830, 1320535400}
{841714728, 1317667877}
{840894251, 1310141916}
{840226137, 1309274625}
Seed was 29678088851250
```
The falsified theory has highlighted something that we forgot.
Math works just fine, but in Java integers can overflow.
### Without static imports
If you prefer the QuickTheories entry points can be brought into scope by implementing an interface, removing the need for static imports.
```java
public class SomeTests implements WithQuickTheories {
@Test
public void addingTwoPositiveIntegersAlwaysGivesAPositiveInteger(){
qt()
.forAll(integers().allPositive()
, integers().allPositive())
.check((i,j) -> i + j > 0);
}
}
```
### Less verbose
The source DSL reads nicely but can be a little verbose. Most of the core generators can also be accessed by importing `org.quicktheories.generators.Generate`. This provides simple static methods that return generators of core types.
```java
import static org.quicktheories.generators.Generate.*;
@Test
public void someProperty() {
qt()
.forAll(range(1, 102), constant(7))
.check((i,c) -> i + c >= 7);
}
```
### Shrinking
QuickTheories supports shrinking.
This means that it doesn't just find a falsifying value and stop. Instead it will try to find other smaller (or "simpler") values that also invalidate the theory.
By default QuickTheories will spend about 100 times more effort looking for smaller values than it did looking for the original falsifying value.
TExcerpt of 23,333 characters
Read on GitHub55
22
5
Philip Potter · Government Digital Service · United Kingdom
3
2
1
1
1
1
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:ec3e04ae2d76f8af, topic:testing