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.
62
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
63
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
63
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
61
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
64
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/d1fa2cb155ab9226f20b87ab0d7a1eb16b8a8b69
61
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
60
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
68
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
68
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/3b519aa7d1a1b66e1d329d694f814e1d8228dc8c
62
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
889
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
557
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/432e6a061f28dda696ba16bc5442328d23b25d93
60
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
61
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
62
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/cdfa43bbe0ecc13757cc6517c9a253de77c3ec56
60
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
61
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
64
NSwag.Commands
NSwag: The OpenAPI/Swagger API toolchain for .NET and TypeScript
62

.NET 10.0

  • No dependencies.

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