Pledge.Testing 0.1.0-alpha.2

This is a prerelease version of Pledge.Testing.
dotnet add package Pledge.Testing --version 0.1.0-alpha.2
                    
NuGet\Install-Package Pledge.Testing -Version 0.1.0-alpha.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pledge.Testing" Version="0.1.0-alpha.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pledge.Testing" Version="0.1.0-alpha.2" />
                    
Directory.Packages.props
<PackageReference Include="Pledge.Testing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pledge.Testing --version 0.1.0-alpha.2
                    
#r "nuget: Pledge.Testing, 0.1.0-alpha.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pledge.Testing@0.1.0-alpha.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pledge.Testing&version=0.1.0-alpha.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pledge.Testing&version=0.1.0-alpha.2&prerelease
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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