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. This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/da7e9894ce22ef8cc02e5acc56e95a6f8cf8f644
51
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
47
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/70048beee894074e9718206a0017d9b080ee66ff
47
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/e3187077455f953200e3c930430808a30f48b82e
46
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/e5f183b656a0e8bc087108130a5a9b54ae94494e
45
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
45
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
44
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
44
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/844a82e37cae48af2ab2ee4f39b41283e6bb4f0e
44
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
44
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/e71b34dbb2c0883145c658bed8814ae45f6fe15e
44
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications. This package was built from the source at: https://github.com/aspnet/Mvc/tree/fb57810f2960730e59db0235207b873c924bc3fd
44
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
44
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/1bf292d47ac2a0ebda07d8a3f00355dd01915ad5
43
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
43
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
43
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
43
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/96103c264e5e8f0485d07018ba27b78cd8227dd2
43
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/564969bca155b40432d101ec35f24a0e81e6afa0
43
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
42

.NET 10.0

  • No dependencies.

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