Microsoft.AspNetCore.TestHost 10.0.0-preview.6.25358.103

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.
22
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/331b52b370cd4e7fe2919d4d4cda27412e2ab1cc
71
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/535da07711bd5e2d8e44c0ea10bd2c8be1a9a584
23
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/561deb05ae2d6680206e3d4a6bc75de699585980
24
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/fbe05294ac5c88be848b4d57d60cb2657874da9b
22
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/371a26f07b23ad77c636332c2dfc0cbd1d8137ba
22
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
22
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
116
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/54142bcb25544b72fac28b1b061e7788c91c4f49
31
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/54e8b61777d42d2b10744d1987438ee5b8c0b24d
22
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/7c810658463f35c39c54d5fb8a8dbbfd463bf747
28
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/860072f7781a10db10fa925ea5c86d91f1e6f2c4
24
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/8af96e042134fb3b2f21df26dd0f32ea1c00dd37
26
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
25
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/a4938d07a5127ffad8466ddf703a6b5b21f4b0c9
24
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/c49ccc8727c620ce1cb8fb431bb3fe8f2e747236
23
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/d6f154cca3863703cf87c8b840eea9cbe20229b2
22
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/fc93e595ceffbb1e3e85532bf454e92a6a80dd6b
23
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/fe4f0d09305ca73aa19976b4521e5c4e223b080e
24

.NET 10.0

  • No dependencies.

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