Microsoft.AspNetCore.TestHost 10.0.1

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.
29
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
32
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
76
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
29
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
33
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/aee5e4080331553ea9dfb7fb388b6d72f715bf6a
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/aspnet/AspNetCore/tree/c04846dc66cc97f71d83a83a15437828435f5d44
30
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/d12868dd7c10ff0433c16b06d3b59d03c40d987a
29
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/2924ca229b3d6c91b7c9eded119b31dfd7aa1fef
29
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
29
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
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/4e7d976438b0fc17f435804e801d5d68d193ec33
123
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
37
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/57512b49997283599b00a6b67d0ccebaec171daf
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/718171eeb4bd236ab4f0d9b1ecd97ecc63ec0be1
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/7c810658463f35c39c54d5fb8a8dbbfd463bf747
36
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
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/8e941eb42f819adb116b881195158b3887a70a1c
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/c49ccc8727c620ce1cb8fb431bb3fe8f2e747236
29
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/c663adee8e64ba5d379fa0edfb8201984a7df7d0
28

.NET 10.0

  • No dependencies.

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