Unit

Customizing Reporting

To emit JSON summaries, push metrics to a dashboard, or customize HTML output, implement IZeReporter or extend ZeUnit.Story's Handlebars templates.

Writing a Custom IZeReporter

IZeReporter inherits IObserver<(ZeTest, Fact)>, giving you three lifecycle callbacks:

using ZeUnit;

public sealed class JsonSummaryReporter : IZeReporter
{
    private int _passed;
    private int _failed;
    private int _skipped;

    public void OnNext((ZeTest, Fact) value)
    {
        var (_, fact) = value;
        switch (fact.State)
        {
            case ZeStatus.Passed:
                _passed++;
                break;
            case ZeStatus.Skipped or ZeStatus.Deferred:
                _skipped++;
                break;
            default:
                _failed++;
                break;
        }
    }

    public void OnError(Exception error) =>
        Console.Error.WriteLine($"Runner error: {error.Message}");

    public void OnCompleted() =>
        Console.WriteLine($"{{\"passed\":{_passed},\"failed\":{_failed},\"skipped\":{_skipped}}}");
}

Register your observer via builder.With(new JsonSummaryReporter()), alongside any built-in reporters.

Customizing HTML Reports with HandlebarsPart

ZeUnit.Story renders sections through IDocumentPart and HandlebarsPart. Subclass HandlebarsPart with a custom CompileSource (StringSource) to customize class headers or test rows:

using ZeUnit.Story;

public sealed class CustomHeaderPart : HandlebarsPart
{
    protected override CompileSource Source { get; } =
        new StringSource("<h2 class='suite-title'>{{name}}</h2>");
}

Reactive Composability

Because ZeGlobal.Unit(builder) returns IObservable<(ZeTest, Fact)>, you can also apply System.Reactive operators such as .Where(...) or .Subscribe(...) directly onto the test stream before awaiting completion.