Pledge.Testing
0.1.0-alpha.2
dotnet add package Pledge.Testing --version 0.1.0-alpha.2
NuGet\Install-Package Pledge.Testing -Version 0.1.0-alpha.2
<PackageReference Include="Pledge.Testing" Version="0.1.0-alpha.2" />
<PackageVersion Include="Pledge.Testing" Version="0.1.0-alpha.2" />
<PackageReference Include="Pledge.Testing" />
paket add Pledge.Testing --version 0.1.0-alpha.2
#r "nuget: Pledge.Testing, 0.1.0-alpha.2"
#:package Pledge.Testing@0.1.0-alpha.2
#addin nuget:?package=Pledge.Testing&version=0.1.0-alpha.2&prerelease
#tool nuget:?package=Pledge.Testing&version=0.1.0-alpha.2&prerelease
Pledge.Testing
Turns Pledge contracts into property-based tests. For each contracted member, CsCheck generates a receiver and arguments, the preconditions throw away the inputs they reject, and the postconditions are the oracle. A failure is shrunk to the smallest input that breaks the contract. Nothing is written twice.
Alpha. The API can still change between pre-releases.
dotnet add package Pledge.Testing --prerelease
using PledgeContracts.Testing;
[Fact]
public void Account_pledges_hold() => PledgeProperties.Check<Account>(iterations: 1_000);
RoundingAccount.Withdraw(decimal) broke its pledge. Postcondition of RoundingAccount.Withdraw violated: Balance == Old(Balance) - amount
Counterexample:
receiver = new RoundingAccount(542m)
amount = 0.00000000000000000001701m
Replay this input with Seed = "0VtUVmxeZKh1" and Iterations = 1. CsCheck: 3 shrinks, 38 skipped, 100 total.
Receivers are built through their widest public constructor. Primitives, strings, enums, dates, records, nullable values and common collections are generated out of the box. Supply your own generator for anything else, or to aim the inputs:
using CsCheck;
// Every decimal the check generates, arguments and constructor parameters alike, now comes from this range.
PledgeProperties.Check<Account>(new PledgePropertyOptions { Iterations = 1_000 }.Use(Gen.Decimal[0m, 10_000m]));
The generator registers each contracted member for testing unless every contract kind is
Ignore, so set <PledgeRegistry>true</PledgeRegistry> in the project under test if your tests
run against a Release build.
For one test per member, use the xUnit or TUnit adapter.
Support
Pledge is MIT-licensed and built in the open. If it saves you a bug or two, consider sponsoring its development.
Source and docs · Design · Issues · License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Pledge.Testing:
| Package | Downloads |
|---|---|
|
Pledge.Testing.TUnit
TUnit adapter for Pledge.Testing. |
|
|
Pledge.Testing.Xunit
xUnit.net v3 adapter for Pledge.Testing. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-alpha.2 | 0 | 10/30/2026 |
| 0.1.0-alpha.1 | 0 | 10/30/2026 |