Microsoft.AspNetCore.TestHost 10.0.0-preview.4.25258.110

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. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52
66
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
66
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/62c098bc170f50feca15916e81cb7f321ffc52ff
65
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/d47e49e9c1e173ac90821f7e89cc38e710274241
65
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/bb01bbf4433e27289b99001b7de6a582879d1835
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/dotnet/aspnetcore/tree/02c6de4ba6022025fcda7581415f310f8c73cdc3
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/7c810658463f35c39c54d5fb8a8dbbfd463bf747
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/c911002ab43b7b989ed67090f2a48d9073d5118d
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
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/432e6a061f28dda696ba16bc5442328d23b25d93
61
NSwag.Commands
NSwag: The Swagger API toolchain for .NET and TypeScript
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
59
NSwag.Commands
NSwag: The Swagger API toolchain for .NET and TypeScript
59
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
58
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/e77cb01b5529c137130757859f09f892dbdd2436
58
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/cccab50fba1c7335fdb48a735246374b5ddd7e69
58
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/8ca3954ca335343ce6dd1d14d8d1c6c3369710b7
57
NSwag.Commands
NSwag: The OpenAPI/Swagger API toolchain for .NET and TypeScript
57
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/471e4710a818849eaf22c5977281d10fd6758616
56
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/d62be99ba6e73feb46d7b64a6b4ce8610dc9040a
56

.NET 10.0

  • No dependencies.

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