https://github.com/kommundsen/conjecture
Property Testing library for .NET
https://github.com/kommundsen/conjecture
mstest nunit property-testing xunit
Last synced: 2 months ago
JSON representation
Property Testing library for .NET
- Host: GitHub
- URL: https://github.com/kommundsen/conjecture
- Owner: kommundsen
- License: mpl-2.0
- Created: 2026-03-25T19:26:53.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-04-10T17:33:54.000Z (3 months ago)
- Last Synced: 2026-04-10T18:19:18.466Z (3 months ago)
- Topics: mstest, nunit, property-testing, xunit
- Language: C#
- Homepage: http://ommundsen.dev/Conjecture/
- Size: 1.3 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE-MIT.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Conjecture.NET
[](https://github.com/kommundsen/Conjecture/actions/workflows/ci.yml)
[](https://github.com/kommundsen/Conjecture/actions/workflows/docs.yml)
[](https://github.com/kommundsen/Conjecture/actions/workflows/release.yml)
[](https://ommundsen.dev/Conjecture/)
[](https://www.nuget.org/packages/Conjecture.Core)
[](https://www.nuget.org/packages/Conjecture.Xunit)
[](https://www.nuget.org/packages/Conjecture.Xunit.V3)
[](https://www.nuget.org/packages/Conjecture.NUnit)
[](https://www.nuget.org/packages/Conjecture.MSTest)
[](https://www.nuget.org/packages/Conjecture.TestingPlatform)
**Property-based testing for .NET** — a ground-up port of Python's [Hypothesis](https://github.com/HypothesisWorks/hypothesis).
## What is it?
Write tests that describe *what* your code should do, and let Conjecture generate hundreds of random inputs to find the edge cases you'd never think of. When it finds a failure, it automatically **shrinks** the input to the smallest possible counterexample — no hand-written cases required.
## Install
Pick the adapter for your test framework:
```bash
dotnet add package Conjecture.Xunit # xUnit v2
dotnet add package Conjecture.Xunit.V3 # xUnit v3
dotnet add package Conjecture.NUnit # NUnit
dotnet add package Conjecture.MSTest # MSTest
```
## Quick Example
```csharp
using Conjecture.Xunit;
public class SortTests
{
[Property]
public bool Sorting_is_idempotent(List items)
{
var sorted = items.OrderBy(x => x).ToList();
var sortedTwice = sorted.OrderBy(x => x).ToList();
return sorted.SequenceEqual(sortedTwice);
}
}
```
Run with `dotnet test`. Conjecture generates random lists, runs the property 100 times, and if it fails, shrinks the input to the minimal failing case.
## Features
- **Automatic test generation** — generates random inputs from type-aware strategies
- **Intelligent shrinking** — finds the smallest failing input via byte-stream minimization
- **LINQ composition** — build complex strategies with `Select`, `Where`, `SelectMany`
- **All major frameworks** — xUnit v2, xUnit v3, NUnit, MSTest
- **Source generators** — derive strategies for your types with `[Arbitrary]`
- **Roslyn analyzers** — catch common mistakes at compile time
- **Stateful testing** — model systems as state machines and explore command sequences
- **Targeted testing** — steer generation toward extremes with `Target.Maximize` / `Target.Minimize`
- **Recursive strategies** — generate bounded-depth trees and self-referential types
- **Example database** — persist failing inputs for automatic regression prevention
- **Structured logging** — structured events for generation, shrinking, and targeting phases
## Documentation
Full documentation is at **[ommundsen.dev/Conjecture](https://ommundsen.dev/Conjecture/)**:
- [Quick Start](https://ommundsen.dev/Conjecture/articles/quick-start.html) — write your first property test in 5 minutes
- [Tutorials](https://ommundsen.dev/Conjecture/articles/tutorials/01-your-first-property-test.html) — learn property-based testing step by step
- [API Reference](https://ommundsen.dev/Conjecture/api/) — auto-generated from source
- [Porting Guide](https://ommundsen.dev/Conjecture/articles/porting-guide.html) — coming from Python Hypothesis?
- [Changelog](CHANGELOG.md)
## Credit
This project is an attempt at a .NET port of [Hypothesis] for Python. The concept of this project builds on and would not be possible without the work of [David R. MacIver](https://www.drmaciver.com/) and [Zac Hatfield-Dodds](https://zhd.dev/), as well as the many other [authors](https://github.com/HypothesisWorks/hypothesis/blob/master/AUTHORS.rst) of the [Hypothesis] project.
## License
Source code: [MPL-2.0](LICENSE.txt) | NuGet packages: [MIT](LICENSE-MIT.txt)
[Hypothesis]: https://github.com/HypothesisWorks/hypothesis