Overview
The Codebelt xUnit extensions solve a practical gap in xUnit testing: tests that allocate disposable resources need deterministic cleanup, tests that depend on Microsoft.Extensions.DependencyInjection need a host, and tests that exercise ASP.NET Core middleware need an in-process TestServer. The four packages in this repository layer these capabilities so a test project picks exactly the scope it needs.
Concepts
The repository is organized as a stack of increasing infrastructure scope. Each layer builds on the one below it, adding hosting, DI, or HTTP pipeline capabilities while preserving the same Test base class and xUnit integration contract.
Structured test lifecycle and output
Codebelt.Extensions.Xunit provides the Test base class that every other package in the stack inherits from. Its constructor accepts an ITestOutputHelper and exposes it as TestOutput, giving every test method a direct path to xUnit diagnostic output through WriteLine and the WriteLines extension. The class implements IDisposable and IAsyncDisposable with three protected hooks: OnDisposeManagedResources for synchronous cleanup, OnDisposeManagedResourcesAsync for async cleanup, and OnDisposeUnmanagedResources for native handles. This replaces scattered try/finally blocks with a single override point.
The same package supplies Match for wildcard-based string assertions with configurable symbols, and InMemoryTestStore<T> for collecting and querying typed objects during a test run. These APIs form the data and assertion primitives that the hosting layers use internally and that consumers use directly in plain unit tests.
Host and dependency injection testing
Codebelt.Extensions.Xunit.Hosting extends the base Test class with Microsoft.Extensions.Hosting support. It provides three factory patterns for different hosting styles: HostTestFactory for classic IHostBuilder scenarios, MinimalHostTestFactory for the modern IHostApplicationBuilder pattern, and ApplicationTestFactory for bootstrapping an existing .NET application entry point directly in tests.
Each factory returns an IHostTest that exposes Host, Configuration, and Environment properties. For test classes that share a host across multiple methods, the package offers HostTest<T> and MinimalHostTest<T> base classes backed by xUnit class fixtures (ManagedHostFixture, ManagedMinimalHostFixture). The ApplicationTest<TEntryPoint, T> base class and BlockingManagedApplicationFixture<TEntryPoint> fixture handle the case where the host is resolved from an entry point assembly rather than configured inline.
ServiceCollectionExtensions.AddXunitTestLogging wires xUnit's ITestOutputHelper into the host's logging pipeline so test output includes log messages from the code under test.
ASP.NET Core integration testing
Codebelt.Extensions.Xunit.Hosting.AspNetCore adds TestServer support on top of the hosting layer. WebApplicationTestFactory and WebApplicationTest<TEntryPoint, T> bootstrap an existing ASP.NET Core application entry point and give tests access to a started TestServer that exercises the real application pipeline without a network listener.
For classic hosting, WebHostTestFactory and MinimalWebHostTestFactory provide Create and RunAsync methods that accept service configuration, middleware pipeline configuration, and host builder delegates. The class-fixture base classes WebHostTest<T> and MinimalWebHostTest<T> expose a ConfigureApplication(IApplicationBuilder) hook so derived tests can define middleware alongside service registration.
BlockingManagedWebApplicationFixture<TEntryPoint> implements IWebApplicationFixture<TEntryPoint> and starts the application host synchronously, making the TestServer available through the Server property for tests that need shared HTTP context across methods.
Layered package selection
The four packages form a strict dependency chain: Codebelt.Extensions.Xunit.App references all three, Codebelt.Extensions.Xunit.Hosting.AspNetCore references Hosting, and Codebelt.Extensions.Xunit.Hosting references the base package. This means a test project can add a single reference at the appropriate layer. The convenience package Codebelt.Extensions.Xunit.App eliminates version management when a project needs the full stack, while the individual packages avoid pulling in infrastructure the tests do not use.
Usage guidance
Start with Codebelt.Extensions.Xunit when tests only need a structured base class, diagnostic output, or in-memory test data. Move to Codebelt.Extensions.Xunit.Hosting when the code under test depends on IServiceCollection, IHost, or configuration. Move to Codebelt.Extensions.Xunit.Hosting.AspNetCore when the code under test runs inside ASP.NET Core middleware or endpoint routing. Avoid installing Codebelt.Extensions.Xunit.App when only one layer is needed, since it brings in the entire stack and its transitive dependencies.
