Microsoft.AspNetCore.TestHost 10.0.0-preview.2.25164.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/d27c0100bc8b9b93eb8102b097c20b40f7de9c49
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/d62be99ba6e73feb46d7b64a6b4ce8610dc9040a
54
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
39
Microsoft.AspNetCore.Mvc.Testing
Support for writing functional tests for MVC applications.
39
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/6a6d775f49623bbd742c02f89d373630668547bb
38
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
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/b8139c5ee58f1708b0e3368a1b241400edd6cbc4
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/dotnet/aspnetcore/tree/6a01dd1e69c8b9bd1ae005ea465ef2bcd26294bf
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/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/fc93e595ceffbb1e3e85532bf454e92a6a80dd6b
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/f050ae044be8bddc002ab88736e4bf78dc822122
27
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/4768f164d522e128f91827810527730f7468fd74
27
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/8486d31e24f30e3fa1809a95699a0adc16f448d7
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/d0ca5a8d20ac50a33d5451e998a5d411a810c8d7
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/febee99db845fd8766a13bdb391a07c3ee90b4ba
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/32e8c8cae5b1a4dd752d0a42a6f8a2813f75f173
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/e77cb01b5529c137130757859f09f892dbdd2436
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/0c26925a185ba2996051c0f37a995ef0a682cf54
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/d4a83b27a44c35c521600e1f30ef688c874415d4
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/3fe12b935c03138f76364dc877a7e069e254b5b2
23

.NET 10.0

  • No dependencies.

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