Table of Contents

Tutorial 5: Framework Adapters

Conjecture works with all major .NET test frameworks. The [Property] attribute and core API are identical across all adapters — only the package name and attribute namespace differ.

Side-by-Side Comparison

using Conjecture.Xunit;

public class MathTests
{
    [Property]
    public bool Addition_is_commutative(int a, int b) => a + b == b + a;

    [Property(MaxExamples = 500)]
    public void Abs_is_non_negative(int value)
    {
        Assume.That(value != int.MinValue);
        Assert.True(Math.Abs(value) >= 0);
    }
}

Package: Conjecture.Xunit

Shared Features

All adapters support the same [Property] properties:

Property Type Default Description
MaxExamples int 100 Examples to generate
Seed ulong 0 (random) Fixed seed for reproducibility
UseDatabase bool true Persist failing examples
MaxStrategyRejections int 5 Max filter rejections per strategy
DeadlineMs int 0 (none) Per-example timeout in ms

All adapters also support:

  • [Example(...)] — explicit test cases
  • [From<T>] — custom strategy providers
  • [FromFactory("Method")] — factory methods
  • Assume.That(condition) — filtering
  • Automatic strategy resolution from parameter types
  • Byte-stream shrinking

Choosing a Framework

The choice is usually dictated by your existing test suite. Conjecture's [Property] tests coexist with your regular [Fact]/[Test]/[TestMethod] tests in the same project.

Next

Tutorial 6: Advanced Patterns — source generators, settings, and the example database.