Microsoft.AspNetCore.TestHost 10.0.0-preview.7.25380.108

About

Microsoft.AspNetCore.TestHost provides an ASP.NET Core web server for testing middleware in isolation.

Key Features

  • Instantiate an app pipeline containing only the components that you need to test
  • Send custom requests to verify middleware behavior

How to Use

To use Microsoft.AspNetCore.TestHost, follow these steps:

Installation

dotnet add package Microsoft.AspNetCore.TestHost

Usage

To set up the TestServer, configure it in your test project. Here's an example:

[Fact]
public async Task MiddlewareTest_ReturnsNotFoundForRequest()
{
    // Build and start a host that uses TestServer
    using var host = await new HostBuilder()
        .ConfigureWebHost(builder =>
        {
            builder.UseTestServer()
                .ConfigureServices(services =>
                {
                    // Add any required services that the middleware uses
                    services.AddMyServices();
                })
                .Configure(app =>
                {
                    // Configure the processing pipeline to use the middleware
                    // for the test
                    app.UseMiddleware<MyMiddleware>();
                });
        })
        .StartAsync();

    var response = await host.GetTestClient().GetAsync("/");

    Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}

Main Types

The main types provided by this package are:

  • TestServer: An IServer implementation for executing tests
  • TestServerOptions: Provides options for configuring a TestServer

Additional Documentation

For additional documentation and examples, refer to the official documentation for testing middleware in ASP.NET Core.

Feedback & Contributing

Microsoft.AspNetCore.TestHost is released as open-source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on Microsoft.AspNetCore.TestHost.

Packages Downloads
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/844a82e37cae48af2ab2ee4f39b41283e6bb4f0e
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/bd1e14b7d16b798de8a874189c89afed755a266c
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/c3acdcac86dad91c3d3fbc3b93ecc6b7ba494bdc
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/c75b3f7a2fb9fe21fd96c93c070fdfa88a2fbe97
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/e81033e094d4663ffd227bb4aed30b76b0631e6d
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/aspnet/Mvc/tree/a6199bbfbab05583f987bae322fb04566841aaea
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/1dcf7acfacf0fe154adcc23270cb0da11ff44ace
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/3f1acb59718cadf111a0a796681e3d3509bb3381
15
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/3fe12b935c03138f76364dc877a7e069e254b5b2
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/4e7d976438b0fc17f435804e801d5d68d193ec33
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/b8139c5ee58f1708b0e3368a1b241400edd6cbc4
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/d827c653b787c07de908240b7746ce34d3e6271e
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/da7e9894ce22ef8cc02e5acc56e95a6f8cf8f644
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/dc5e11abdb05b322f4b74b3afbcfb352fe984b2e
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/e882394a7bb38930da748291fe2c2ceaa6a80588
14
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/f9ae0f5d30be2de3c0de61b5673bd8873231d70a
14

.NET 10.0

  • No dependencies.

Version Downloads Last updated
10.0.1 2 18.12.2025
10.0.0 1 18.12.2025
10.0.0-rc.2.25502.107 1 18.12.2025
10.0.0-rc.1.25451.107 1 18.12.2025
10.0.0-preview.7.25380.108 1 18.12.2025
10.0.0-preview.6.25358.103 2 06.08.2025
10.0.0-preview.5.25277.114 4 11.06.2025
10.0.0-preview.4.25258.110 4 11.06.2025
10.0.0-preview.3.25172.1 6 18.04.2025
10.0.0-preview.2.25164.1 6 14.04.2025
10.0.0-preview.1.25120.3 7 13.03.2025
9.0.11 1 18.12.2025
9.0.10 1 18.12.2025
9.0.9 4 16.09.2025
9.0.8 4 16.09.2025
9.0.7 5 05.08.2025
9.0.6 6 28.06.2025
9.0.5 7 10.06.2025
9.0.4 10 25.04.2025
9.0.3 11 13.03.2025
9.0.2 11 18.02.2025
9.0.1 11 19.02.2025
9.0.0 11 19.02.2025
9.0.0-rc.2.24474.3 7 19.02.2025
9.0.0-rc.1.24452.1 7 19.02.2025
9.0.0-preview.7.24406.2 8 19.02.2025
9.0.0-preview.6.24328.4 7 19.02.2025
9.0.0-preview.5.24306.11 7 19.02.2025
9.0.0-preview.4.24267.6 7 20.02.2025
9.0.0-preview.3.24172.13 7 12.02.2025
9.0.0-preview.2.24128.4 7 19.02.2025
9.0.0-preview.1.24081.5 7 20.02.2025
8.0.22 1 18.12.2025
8.0.21 1 18.12.2025
8.0.20 1 18.12.2025
8.0.19 1 18.12.2025
8.0.18 2 06.08.2025
8.0.17 3 29.06.2025
8.0.16 3 11.06.2025
8.0.15 6 17.04.2025
8.0.14 9 13.03.2025
8.0.13 8 22.02.2025
8.0.12 8 20.02.2025
8.0.11 8 19.02.2025
8.0.10 8 19.02.2025
8.0.8 11 19.02.2025
8.0.7 10 25.02.2025
8.0.6 11 19.02.2025
8.0.5 11 20.02.2025
8.0.4 11 19.02.2025
8.0.3 11 19.02.2025
8.0.2 11 20.02.2025
8.0.1 11 20.02.2025
8.0.0 11 19.02.2025
8.0.0-rc.2.23480.2 7 20.02.2025
8.0.0-rc.1.23421.29 7 25.02.2025
8.0.0-preview.7.23375.9 7 19.02.2025
8.0.0-preview.6.23329.11 11 19.02.2025
8.0.0-preview.5.23302.2 7 25.02.2025
8.0.0-preview.4.23260.4 7 19.02.2025
8.0.0-preview.3.23177.8 7 19.02.2025
8.0.0-preview.2.23153.2 7 19.02.2025
8.0.0-preview.1.23112.2 7 19.02.2025
7.0.20 8 01.03.2025
7.0.19 8 19.02.2025
7.0.18 8 19.02.2025
7.0.17 9 25.02.2025
7.0.16 8 20.02.2025
7.0.15 8 20.02.2025
7.0.14 8 25.02.2025
7.0.13 8 25.02.2025
7.0.12 8 20.02.2025
7.0.11 8 25.02.2025
7.0.10 8 26.02.2025
7.0.9 11 20.02.2025
7.0.8 11 18.02.2025
7.0.7 11 18.02.2025
7.0.5 11 19.02.2025
7.0.4 11 19.02.2025
7.0.3 11 19.02.2025
7.0.2 11 19.02.2025
7.0.1 11 20.02.2025
7.0.0 12 25.02.2025
7.0.0-rc.2.22476.2 7 25.02.2025
7.0.0-rc.1.22427.2 7 25.02.2025
7.0.0-preview.7.22376.6 7 19.02.2025
7.0.0-preview.6.22330.3 7 19.02.2025
7.0.0-preview.5.22303.8 8 25.02.2025
7.0.0-preview.4.22251.1 8 18.02.2025
7.0.0-preview.3.22178.4 7 25.02.2025
7.0.0-preview.2.22153.2 7 24.02.2025
7.0.0-preview.1.22109.13 7 20.02.2025
6.0.36 8 25.02.2025
6.0.35 8 28.02.2025
6.0.33 8 25.02.2025
6.0.32 8 22.02.2025
6.0.31 8 25.02.2025
6.0.30 8 25.02.2025
6.0.29 8 28.02.2025
6.0.28 8 19.02.2025
6.0.27 8 25.02.2025
6.0.26 8 01.03.2025
6.0.25 7 19.02.2025
6.0.24 8 25.02.2025
6.0.23 8 23.02.2025
6.0.22 8 19.02.2025
6.0.21 8 24.02.2025
6.0.20 8 23.02.2025
6.0.19 8 19.02.2025
6.0.18 8 25.02.2025
6.0.16 8 01.03.2025
6.0.15 8 25.02.2025
6.0.14 8 25.02.2025
6.0.13 9 23.02.2025
6.0.12 8 19.02.2025
6.0.11 8 20.02.2025
6.0.10 9 28.02.2025
6.0.9 11 21.02.2025
6.0.8 9 25.02.2025
6.0.7 11 24.02.2025
6.0.6 12 25.02.2025
6.0.5 12 25.02.2025
6.0.4 12 25.02.2025
6.0.3 11 18.02.2025
6.0.2 11 20.02.2025
6.0.1 10 25.02.2025
6.0.0 12 28.02.2025
6.0.0-rc.2.21480.10 7 25.02.2025
6.0.0-rc.1.21452.15 7 25.02.2025
6.0.0-preview.7.21378.6 7 20.02.2025
6.0.0-preview.6.21355.2 7 25.02.2025
6.0.0-preview.5.21301.17 7 25.02.2025
6.0.0-preview.4.21253.5 7 25.02.2025
6.0.0-preview.3.21201.13 7 16.02.2025
6.0.0-preview.2.21154.6 7 20.02.2025
6.0.0-preview.1.21103.6 7 16.02.2025
5.0.17 8 20.02.2025
5.0.16 8 23.02.2025
5.0.15 8 20.02.2025
5.0.14 8 20.02.2025
5.0.13 9 25.02.2025
5.0.12 8 19.02.2025
5.0.11 8 19.02.2025
5.0.10 8 16.02.2025
5.0.9 11 19.02.2025
5.0.8 11 19.02.2025
5.0.7 11 18.02.2025
5.0.6 12 19.02.2025
5.0.5 12 19.02.2025
5.0.4 8 13.03.2025
5.0.3 11 18.02.2025
5.0.2 11 12.02.2025
5.0.1 11 19.02.2025
5.0.0 12 20.02.2025
5.0.0-rc.2.20475.17 6 25.02.2025
5.0.0-rc.1.20451.17 7 24.02.2025
5.0.0-preview.8.20414.8 7 13.02.2025
5.0.0-preview.7.20365.19 7 19.02.2025
5.0.0-preview.6.20312.15 7 19.02.2025
5.0.0-preview.5.20279.2 7 25.02.2025
5.0.0-preview.4.20257.10 7 13.02.2025
5.0.0-preview.3.20215.14 7 20.02.2025
5.0.0-preview.2.20167.3 8 20.02.2025
5.0.0-preview.1.20124.5 8 19.02.2025
3.1.32 8 19.02.2025
3.1.31 8 19.02.2025
3.1.30 8 20.02.2025
3.1.29 8 19.02.2025
3.1.28 8 20.02.2025
3.1.27 8 19.02.2025
3.1.26 8 25.02.2025
3.1.25 8 20.02.2025
3.1.24 8 19.02.2025
3.1.23 8 20.02.2025
3.1.22 8 19.02.2025
3.1.21 8 24.02.2025
3.1.20 8 19.02.2025
3.1.19 8 19.02.2025
3.1.18 8 19.02.2025
3.1.17 8 19.02.2025
3.1.16 8 19.02.2025
3.1.15 8 18.02.2025
3.1.14 8 20.02.2025
3.1.13 8 23.02.2025
3.1.12 8 19.02.2025
3.1.11 8 19.02.2025
3.1.10 8 19.02.2025
3.1.9 11 19.02.2025
3.1.8 11 20.02.2025
3.1.7 11 13.02.2025
3.1.6 11 18.02.2025
3.1.5 11 19.02.2025
3.1.4 11 19.02.2025
3.1.3 11 19.02.2025
3.1.2 11 19.02.2025
3.1.1 11 19.02.2025
3.1.0 11 19.02.2025
3.1.0-preview3.19555.2 8 20.02.2025
3.1.0-preview2.19528.8 8 19.02.2025
3.1.0-preview1.19508.20 8 25.02.2025
3.0.3 11 19.02.2025
3.0.2 11 20.02.2025
3.0.0 11 18.02.2025
3.0.0-rc1.19457.4 11 25.02.2025
3.0.0-preview9.19424.4 8 25.02.2025
3.0.0-preview8.19405.7 7 19.02.2025
3.0.0-preview7.19365.7 8 18.02.2025
3.0.0-preview6.19307.2 8 25.02.2025
3.0.0-preview5-19227-01 7 25.02.2025
3.0.0-preview4-19216-03 7 25.02.2025
3.0.0-preview3-19153-02 8 20.02.2025
3.0.0-preview-19075-0444 7 25.02.2025
3.0.0-preview-18579-0056 6 25.02.2025
2.3.0 11 19.02.2025
2.2.0 11 16.02.2025
2.2.0-preview3-35497 7 20.02.2025
2.2.0-preview2-35157 7 12.02.2025
2.2.0-preview1-35029 7 01.03.2025
2.1.1 11 19.02.2025
2.1.0 11 15.02.2025
2.1.0-rc1-final 8 25.02.2025
2.1.0-preview2-final 9 13.02.2025
2.1.0-preview1-final 7 19.02.2025
2.0.3 12 19.02.2025
2.0.2 11 19.02.2025
2.0.1 12 19.02.2025
2.0.0 11 19.02.2025
2.0.0-preview2-final 9 13.02.2025
2.0.0-preview1-final 7 18.02.2025
1.1.3 11 20.02.2025
1.1.2 11 18.02.2025
1.1.1 10 20.02.2025
1.1.0 11 25.02.2025
1.1.0-preview1-final 8 20.02.2025
1.0.5 12 28.02.2025
1.0.4 12 20.02.2025
1.0.3 11 19.02.2025
1.0.2 12 25.02.2025
1.0.1 11 25.02.2025
1.0.0 11 25.02.2025
1.0.0-rc2-final 9 25.02.2025