Unit

Returning Results & Custom Test Runners

ZeUnit discovers test methods by inspecting their return types against the active ZeTestRunner implementations discovered by IZeTestRunnerDiscovery.

Built-In Return Types

DefaultTestRunnerDiscovery registers four ZeTestRunner implementations out of the box:

RunnerReturn TypeSemantics
ObjectTestRunnerFactOne result, synchronous
TaskTestRunnerTask<Fact>One result, asynchronous
EnumerableTestRunnerIEnumerable<Fact>Many results, synchronous
ObservableTestRunnerIObservable<Fact>Many results, reactive / async

Every runner turns thrown unhandled exceptions into an AssertError wrapped inside a Fact, ensuring reporters and VSTest always receive a structured failure instead of crashing the stream.

Example Across All Four Shapes

public class ResultShapesSuite
{
    public Fact Immediate() => "ok".Is("ok");

    public async Task<Fact> Delayed()
    {
        await Task.Delay(10);
        return true;
    }

    public IEnumerable<Fact> MultipleSync()
    {
        yield return 1.Is(1);
        yield return 2.Is(2);
    }

    public IObservable<Fact> StreamingAsync() =>
        Observable.Range(1, 3).Select(i => i.IsBetween(1, 3));
}

Supporting Custom Return Types

To execute methods returning a custom domain type (for example ValueTask<Fact>), inherit ZeTestRunner<TReturnType> inside ZeUnit or supply a custom IZeTestRunnerDiscovery (or ListTestRunnerDiscovery) to new ZeBuilder(customDiscovery).

Test Adapter Aggregation

When a single IEnumerable<Fact> or IObservable<Fact> method yields multiple Fact values, VisualStudioZeUnitTestAdapter aggregates them 1-to-1 per TestCase and fails the test case if any emitted Fact fails or errors.