
▲ 6 r/dotnet
QuickTestr: a lightweight property-based testing DSL for C#
>No fuss, just fuzz.
I've just open sourced QuickTestr.
It's built on a lower-level engine (QuickCheckr) but aims to keep the common cases simple and readable.
Repo: https://github.com/kilfour/QuickTestr
For when you're interested in property-based testing but do not care about category theory or pursuing a PhD.
Testr
.Named("Reversing a list of integers results in the same list")
.For(Fuzzr.Int().Many(0, 10).ToList())
.Assert(a =>
{
var reversed = new List<int>(a);
reversed.Reverse();
reversed.Reverse();
return reversed.SequenceEqual(a);
});
It also supports oracle/golden-model testing:
Testr.Named("Calculator Oracle")
.For(ItemFuzzr.Get.Many(1, 20).ToList())
.Expected(Calculator.Total)
.Actual(CalculatorNew.Total);
Docs:
- Getting Started: https://github.com/kilfour/QuickTestr/blob/main/Docs/doc.md
- Shrinking Challenges: https://github.com/kilfour/QuickTestr/blob/main/Docs/challenges.md
- An Example of Refactoring Legacy Code: https://github.com/kilfour/QuickTestr/blob/main/Examples/dantes-calculator.md
On it being 0.x.:
The built-in reducers are minimal (mostly integer reduction).
The interesting shrinking comes from structural shrinking, irrelevance shrinking, and custom reducers. All of which you can plug in.
The engine underneath has seen real use in teaching.
The API surface is what's new.
Looking for:
Ideas, bug reports, API feedback, and honest opinions.
u/Glum-Sea4456 — 14 days ago