Skip to content

Testing and Docs

github-actions[bot] edited this page Nov 30, 2026 · 5 revisions

Testing, Doc-Tests & Static API Docs

Ferrous brings Rust's testing and documentation workflow (trybuild, cargo test --doc, cargo doc, and cargo new) to .NET.

Ferrous.Testing

Install in your test project:

dotnet add package Ferrous.Testing

Compile-Fail Testing (CompileAssert)

Verify that invalid usages of [Typestate], [Consuming], [BorrowMut], [NoDefault], or [Closed] fail compilation with specific FE* diagnostics:

using Ferrous.Testing;

CompileAssert.Fails("""
    using Ferrous;
    public static class Demo
    {
        public static void Take([Consuming] string s) { }
        public static void Run()
        {
            var buf = "payload";
            Take(buf);
            _ = buf.Length;
        }
    }
    """, "FE0200");

Framework-Agnostic Result & Option Assertions

Works with xUnit, NUnit, MSTest, and TUnit:

int port = ParsePort("8080").AssertOk();
string err = ParsePort("abc").AssertErr();
string name = FindUser(1).AssertSome();
FindUser(999).AssertNone();

Zero-Allocation Assertions (AllocAssert)

Unit-test companion to [NoAlloc]:

int sum = AllocAssert.Zero(static () => Result.Ok<int, string>(41).Map(static x => x + 1).UnwrapOr(0));

Executable Doc-Tests (dotnet fe doctest & dotnet fe test)

Run all /// <example><code> XML doc blocks and fenced ```csharp Markdown snippets:

dotnet fe doctest ./src
dotnet fe test .

Supported directives: no_run, ignore, compile_fail, and compile_fail(FE0200).

Zero-Config Static API Docs (dotnet fe doc)

Generate a searchable static HTML API docs site with Roslyn syntax highlighting, full XML docs (exceptions, params, returns, examples), cross-page <see cref> links, <inheritdoc /> expansion, [DiscriminatedUnion] variant tables, [Newtype] wrapper cards, and embedded Mermaid [Typestate] graphs (see Typestate Protocol for a rendered diagram example):

dotnet fe doc ./src --output ./docs-site --title "My API Reference" --logo ./assets/icon.png --open

For a live site generated by dotnet fe doc, browse Ferrous's own API Reference.

Supply-Chain Hygiene & Project Template

# Audit lockfiles, SemVer validation, NativeAOT readiness, and NuGet CVEs
dotnet fe audit . --packages --allow-licenses MIT --lockfile --semver --aot --cve

# Scaffold a new strict Ferrous project
dotnet new install Ferrous.Templates
dotnet new ferrous -n MyApp

Property-Based Testing (PropAssert & Gen<T>)

Zero-dependency, proptest-style property testing with deterministic replay seeds and automatic counterexample shrinking:

using Ferrous.Testing;

PropAssert.ForAll(
    Gen.NonEmptyString(maxLength: 32),
    s => !string.IsNullOrWhiteSpace(s.Value) && s.Length >= 1,
    iterations: 200,
    seed: 42);

PropAssert.ForAll(
    Gen.Int(-1000, 1000),
    Gen.Int(-1000, 1000),
    (a, b) => a + b == b + a);

Built-in generators include Gen.Int, Gen.Long, Gen.Bool, Gen.Double, Gen.Decimal, Gen.Guid, Gen.DateTimeOffset, Gen.String, Gen.NonEmptyString, Gen.NonZeroInt, Gen.Option, Gen.Result, Gen.OneOf, Gen.OneOfGen, Gen.Newtype, Gen.List, plus .Select(...) and .Where(...) combinators. Both sync (PropAssert.ForAll, up to 3 arguments) and async (PropAssert.ForAllAsync) properties are supported, with automatic counterexample shrinking and exact seed reporting in FerrousAssertionException.

Clone this wiki locally