Microsoft.AspNetCore.TestHost 10.0.0

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.
43
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
44
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/0a2e366eaf4d29b24b9a98e5782a04bef573189e
43
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/2b7e994b8a304700a09617ffc5052f0d943bbcba
44
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/7e8bbb70b266b2fdaf0b11ec47fb3077761fb6bf
42
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/9699b939f94b7524a178821d78addefa5af5d750
44
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/cf2c5c9c6dca430b97aa96429b84d0da07eb77f1
45
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
46
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/02c6de4ba6022025fcda7581415f310f8c73cdc3
43
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/1d696053fcd6735aaac1902afdb0b92edbf43e71
47
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/2aa401550574f93402eba13ff9a4827ef01a2f3a
44
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/39e0501ee91dcf2b9b885d647795184815fb0408
42
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/3eeb12e106b9e913c3a4dec1a7d16da7b74149eb
835
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
501
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/8e941eb42f819adb116b881195158b3887a70a1c
45
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/98a853b20131fd59b37076dd3699d8c7f62b24cb
44
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/d634f2bd1ad6e319f26ff0f1d7ada5539158a19f
42
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/e56abc45c4f8adc518abfc11a59849d616431e2c
44
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/fb4b5a21ebd67b31fff4ddf5c039181da504c932
48
NSwag.Commands
NSwag: The OpenAPI/Swagger API toolchain for .NET and TypeScript
44

.NET 10.0

  • No dependencies.

Version Downloads Last updated
10.0.0 20 11/13/2025
10.0.0-rc.2.25502.107 18 10/17/2025
10.0.0-rc.1.25451.107 20 09/10/2025
10.0.0-preview.7.25380.108 20 08/15/2025
10.0.0-preview.6.25358.103 23 07/19/2025
10.0.0-preview.5.25277.114 23 06/08/2025
10.0.0-preview.4.25258.110 28 05/15/2025
10.0.0-preview.3.25172.1 28 04/19/2025
10.0.0-preview.2.25164.1 30 03/30/2025
10.0.0-preview.1.25120.3 31 03/05/2025
9.0.11 13 11/13/2025
9.0.10 17 10/16/2025
9.0.9 16 09/10/2025
9.0.8 22 08/10/2025
9.0.7 22 07/10/2025
9.0.6 22 06/13/2025
9.0.5 29 05/16/2025
9.0.4 25 04/10/2025
9.0.3 28 03/12/2025
9.0.2 33 03/05/2025
9.0.1 30 01/24/2025
9.0.0 40 12/04/2024
9.0.0-rc.2.24474.3 35 11/29/2024
9.0.0-rc.1.24452.1 41 11/14/2024
9.0.0-preview.7.24406.2 39 11/14/2024
9.0.0-preview.6.24328.4 27 12/01/2024
9.0.0-preview.5.24306.11 30 12/04/2024
9.0.0-preview.4.24267.6 32 11/14/2024
9.0.0-preview.3.24172.13 34 12/02/2024
9.0.0-preview.2.24128.4 46 05/05/2024
9.0.0-preview.1.24081.5 33 12/10/2024
8.0.22 16 11/13/2025
8.0.21 16 10/16/2025
8.0.20 17 09/10/2025
8.0.19 16 08/07/2025
8.0.18 23 07/10/2025
8.0.17 24 06/13/2025
8.0.16 31 05/17/2025
8.0.15 34 04/10/2025
8.0.14 24 03/12/2025
8.0.13 28 03/05/2025
8.0.12 36 01/23/2025
8.0.11 34 12/03/2024
8.0.10 32 12/12/2024
8.0.8 35 12/03/2024
8.0.7 36 12/02/2024
8.0.6 30 12/06/2024
8.0.5 37 12/02/2024
8.0.4 33 12/03/2024
8.0.3 30 01/02/2025
8.0.2 32 12/09/2024
8.0.1 39 02/04/2024
8.0.0 382 04/11/2024
8.0.0-rc.2.23480.2 34 06/01/2024
8.0.0-rc.1.23421.29 33 06/01/2024
8.0.0-preview.7.23375.9 27 12/02/2024
8.0.0-preview.6.23329.11 47 08/15/2023
8.0.0-preview.5.23302.2 33 12/06/2024
8.0.0-preview.4.23260.4 36 12/02/2024
8.0.0-preview.3.23177.8 34 12/11/2024
8.0.0-preview.2.23153.2 30 12/11/2024
8.0.0-preview.1.23112.2 29 12/04/2024
7.0.20 34 12/17/2024
7.0.19 27 12/26/2024
7.0.18 28 12/13/2024
7.0.17 39 12/02/2024
7.0.16 39 12/04/2024
7.0.15 29 11/30/2024
7.0.14 32 12/05/2024
7.0.13 34 12/07/2024
7.0.12 31 12/08/2024
7.0.11 32 12/04/2024
7.0.10 36 12/15/2024
7.0.9 36 11/14/2024
7.0.8 32 12/01/2024
7.0.7 43 06/16/2023
7.0.5 43 06/16/2023
7.0.4 38 11/29/2024
7.0.3 42 07/13/2023
7.0.2 36 12/01/2024
7.0.1 28 12/03/2024
7.0.0 32 12/02/2024
7.0.0-rc.2.22476.2 35 06/01/2024
7.0.0-rc.1.22427.2 35 06/01/2024
7.0.0-preview.7.22376.6 34 12/02/2024
7.0.0-preview.6.22330.3 27 12/11/2024
7.0.0-preview.5.22303.8 31 11/14/2024
7.0.0-preview.4.22251.1 29 11/14/2024
7.0.0-preview.3.22178.4 39 12/03/2024
7.0.0-preview.2.22153.2 30 12/04/2024
7.0.0-preview.1.22109.13 38 12/13/2024
6.0.36 30 11/14/2024
6.0.35 31 11/29/2024
6.0.33 42 11/30/2024
6.0.32 34 12/04/2024
6.0.31 37 12/03/2024
6.0.30 41 11/28/2024
6.0.29 31 12/10/2024
6.0.28 37 12/05/2024
6.0.27 28 11/14/2024
6.0.26 29 12/02/2024
6.0.25 30 11/14/2024
6.0.24 31 12/09/2024
6.0.23 35 12/02/2024
6.0.22 31 12/02/2024
6.0.21 35 12/01/2024
6.0.20 34 12/02/2024
6.0.19 38 12/09/2024
6.0.18 31 12/02/2024
6.0.16 33 12/09/2024
6.0.15 27 12/03/2024
6.0.14 35 11/14/2024
6.0.13 32 12/02/2024
6.0.12 28 12/05/2024
6.0.11 34 11/29/2024
6.0.10 31 11/29/2024
6.0.9 32 11/14/2024
6.0.8 34 12/02/2024
6.0.7 32 11/30/2024
6.0.6 34 11/29/2024
6.0.5 41 12/02/2024
6.0.4 32 12/02/2024
6.0.3 34 12/06/2024
6.0.2 36 11/14/2024
6.0.1 32 11/14/2024
6.0.0 36 05/03/2024
6.0.0-rc.2.21480.10 35 06/01/2024
6.0.0-rc.1.21452.15 35 11/03/2022
6.0.0-preview.7.21378.6 34 12/04/2024
6.0.0-preview.6.21355.2 29 12/12/2024
6.0.0-preview.5.21301.17 30 11/29/2024
6.0.0-preview.4.21253.5 33 12/03/2024
6.0.0-preview.3.21201.13 32 11/29/2024
6.0.0-preview.2.21154.6 33 05/30/2024
6.0.0-preview.1.21103.6 32 12/09/2024
5.0.17 31 12/03/2024
5.0.16 38 12/03/2024
5.0.15 34 12/13/2024
5.0.14 30 12/01/2024
5.0.13 34 12/10/2024
5.0.12 29 12/03/2024
5.0.11 31 12/01/2024
5.0.10 39 11/29/2024
5.0.9 28 12/03/2024
5.0.8 33 12/04/2024
5.0.7 32 11/14/2024
5.0.6 32 12/06/2024
5.0.5 39 05/04/2024
5.0.4 36 12/02/2024
5.0.3 32 12/02/2024
5.0.2 34 12/02/2024
5.0.1 36 12/02/2024
5.0.0 39 11/03/2022
5.0.0-rc.2.20475.17 34 06/01/2024
5.0.0-rc.1.20451.17 32 06/01/2024
5.0.0-preview.8.20414.8 33 12/02/2024
5.0.0-preview.7.20365.19 28 12/03/2024
5.0.0-preview.6.20312.15 33 12/02/2024
5.0.0-preview.5.20279.2 26 12/03/2024
5.0.0-preview.4.20257.10 36 11/29/2024
5.0.0-preview.3.20215.14 37 12/10/2024
5.0.0-preview.2.20167.3 30 12/01/2024
5.0.0-preview.1.20124.5 25 12/03/2024
3.1.32 625 05/11/2023
3.1.31 40 11/14/2024
3.1.29 33 12/02/2024
3.1.28 33 12/02/2024
3.1.27 30 12/03/2024
3.1.26 28 12/03/2024
3.1.25 40 11/14/2024
3.1.24 38 12/01/2024
3.1.23 26 12/04/2024
3.1.22 29 12/01/2024
3.1.21 33 12/02/2024
3.1.20 30 12/13/2024
3.1.19 31 12/04/2024
3.1.18 39 12/01/2024
3.1.17 33 12/10/2024
3.1.16 37 12/13/2024
3.1.15 37 11/14/2024
3.1.14 33 12/04/2024
3.1.13 30 12/03/2024
3.1.12 31 11/29/2024
3.1.11 39 12/02/2024
3.1.10 33 12/04/2024
3.1.9 36 12/06/2024
3.1.8 30 12/06/2024
3.1.7 34 12/07/2024
3.1.6 32 12/01/2024
3.1.5 35 11/14/2024
3.1.4 36 12/01/2024
3.1.3 29 11/14/2024
3.1.2 35 11/14/2024
3.1.1 31 11/14/2024
3.1.0 31 12/02/2024
3.1.0-preview3.19555.2 38 06/01/2024
3.1.0-preview2.19528.8 38 06/01/2024
3.1.0-preview1.19508.20 38 12/02/2024
3.0.3 35 11/14/2024
3.0.2 37 11/12/2024
3.0.0 46 11/03/2022
3.0.0-rc1.19457.4 29 06/01/2024
3.0.0-preview9.19424.4 37 06/01/2024
3.0.0-preview8.19405.7 35 06/01/2024
3.0.0-preview7.19365.7 36 06/01/2024
3.0.0-preview6.19307.2 42 06/01/2024
3.0.0-preview5-19227-01 27 12/03/2024
3.0.0-preview4-19216-03 30 12/01/2024
3.0.0-preview3-19153-02 28 11/14/2024
3.0.0-preview-19075-0444 29 11/14/2024
3.0.0-preview-18579-0056 29 12/02/2024
2.3.0 28 01/22/2025
2.2.0 37 12/03/2024
2.2.0-preview3-35497 30 06/01/2024
2.2.0-preview2-35157 28 06/01/2024
2.2.0-preview1-35029 35 06/01/2024
2.1.1 40 11/03/2022
2.1.0 37 12/09/2024
2.1.0-rc1-final 34 05/29/2024
2.1.0-preview2-final 45 06/01/2024
2.1.0-preview1-final 31 06/01/2024
2.0.3 36 12/02/2024
2.0.2 37 12/02/2024
2.0.1 36 12/06/2024
2.0.0 31 11/14/2024
2.0.0-preview2-final 34 06/01/2024
2.0.0-preview1-final 36 06/01/2024
1.1.3 36 12/05/2024
1.1.2 33 11/14/2024
1.1.1 31 11/14/2024
1.1.0 29 11/30/2024
1.1.0-preview1-final 38 06/01/2024
1.0.5 35 12/02/2024
1.0.4 43 12/01/2024
1.0.3 42 05/03/2024
1.0.2 33 11/14/2024
1.0.1 32 12/02/2024
1.0.0 32 12/02/2024
1.0.0-rc2-final 44 05/29/2024