Microsoft.AspNetCore.TestHost 10.0.0-preview.3.25172.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. This package was built from the source code at https://github.com/aspnet/AspNetCore/tree/aee5e4080331553ea9dfb7fb388b6d72f715bf6a
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/3b519aa7d1a1b66e1d329d694f814e1d8228dc8c
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/e882394a7bb38930da748291fe2c2ceaa6a80588
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/d504a7b7dab277712646747e9f5cce0d9507245e
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/aspnet/AspNetCore/tree/2b7e994b8a304700a09617ffc5052f0d943bbcba
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/bd1e14b7d16b798de8a874189c89afed755a266c
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/1f050242559e7b90ff6c4ee7f99d92b3a5af5a62
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
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/cf2c5c9c6dca430b97aa96429b84d0da07eb77f1
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/9699b939f94b7524a178821d78addefa5af5d750
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/8e941eb42f819adb116b881195158b3887a70a1c
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/3c37ef8f5358abb303c05d299f029fca7d867d56
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/e56abc45c4f8adc518abfc11a59849d616431e2c
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/ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52
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/2670c128d522473e146ff9f8159bfffdfe694cd9
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/62c098bc170f50feca15916e81cb7f321ffc52ff
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
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/Mvc/tree/a6199bbfbab05583f987bae322fb04566841aaea
23
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
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/610fe433e07b32ed451ed99d07df63be47c29050
23

.NET 10.0

  • No dependencies.

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