Microsoft.AspNetCore.TestHost
10.0.0
Prefix Reserved
dotnet add package Microsoft.AspNetCore.TestHost --version 10.0.0
NuGet\Install-Package Microsoft.AspNetCore.TestHost -Version 10.0.0
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
paket add Microsoft.AspNetCore.TestHost --version 10.0.0
#r "nuget: Microsoft.AspNetCore.TestHost, 10.0.0"
#:package Microsoft.AspNetCore.TestHost@10.0.0
#addin nuget:?package=Microsoft.AspNetCore.TestHost&version=10.0.0
#tool nuget:?package=Microsoft.AspNetCore.TestHost&version=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: AnIServerimplementation for executing testsTestServerOptions: Provides options for configuring aTestServer
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.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (186)
Showing the top 5 NuGet packages that depend on Microsoft.AspNetCore.TestHost:
| Package | 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/dotnet/tree/b0f34d51fccc69fd334253924abd8d6853fad7aa |
|
|
Rystem.Test.XUnit
Rystem is a open-source framework to improve the System namespace in .Net |
|
|
Acheve.TestHost
Achve.TestHost is a nuget package to improve TestServer experiences. For more information see http://github.com/Xabaril/Acheve.TestHost |
|
|
MyTested.AspNetCore.Mvc.Abstractions
My Tested ASP.NET Core MVC common abstractions and interfaces. |
|
|
Volo.Abp.AspNetCore.TestBase
Package Description |
GitHub repositories (224)
Showing the top 20 popular GitHub repositories that depend on Microsoft.AspNetCore.TestHost:
| Repository | Stars |
|---|---|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
|
|
aspnetboilerplate/aspnetboilerplate
ASP.NET Boilerplate - Web Application Framework
|
|
|
dotnet/eShop
A reference .NET application implementing an eCommerce site
|
|
|
dotnet/yarp
A toolkit for developing high-performance HTTP reverse proxy applications.
|
|
|
ThreeMammals/Ocelot
.NET API Gateway
|
|
|
RicoSuter/NSwag
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
|
|
|
ldqk/Masuit.Tools
全龄段友好的C#万能工具库,码数吐司库,包含一些常用的操作类,大都是静态类,加密解密,反射操作,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展、Excel导出等常用封装。诸多功能集一身,代码量不到2MB!
|
|
|
FastEndpoints/FastEndpoints
A light-weight REST API development framework for ASP.NET 8 and newer.
|
|
|
kurrent-io/KurrentDB
KurrentDB is a database that's engineered for modern software applications and event-driven architectures. Its event-native design simplifies data modeling and preserves data integrity while the integrated streaming engine solves distributed messaging challenges and ensures data consistency.
|
|
|
ChilliCream/graphql-platform
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Nitro the awesome Monaco based GraphQL IDE.
|
|
|
aspnet/Mvc
[Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore
|
|
|
domaindrivendev/Swashbuckle.AspNetCore
Swagger tools for documenting API's built on ASP.NET Core
|
|
|
microsoft/agent-framework
A framework for building, orchestrating and deploying AI agents and multi-agent workflows with support for Python and .NET.
|
|
|
dotnet/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
openiddict/openiddict-core
Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
|
|
|
dotnetcore/Util
Util是一个.Net平台下的应用框架,旨在提升中小团队的开发能力,由工具类、分层架构基类、Ui组件,配套代码生成模板,权限等组成。
|
|
|
opserver/Opserver
Stack Exchange's Monitoring System
|
|
|
grpc/grpc-dotnet
gRPC for .NET
|
|
|
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
|
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 10.0.0 | 52,437 | 11/11/2025 | |
| 10.0.0-rc.2.25502.107 | 82,229 | 10/14/2025 | |
| 10.0.0-rc.1.25451.107 | 72,855 | 9/9/2025 | |
| 10.0.0-preview.7.25380.108 | 34,063 | 8/12/2025 | |
| 10.0.0-preview.6.25358.103 | 6,106 | 7/15/2025 | |
| 10.0.0-preview.5.25277.114 | 34,463 | 6/6/2025 | |
| 10.0.0-preview.4.25258.110 | 5,198 | 5/12/2025 | |
| 10.0.0-preview.3.25172.1 | 7,086 | 4/10/2025 | |
| 10.0.0-preview.2.25164.1 | 2,712 | 3/18/2025 | |
| 10.0.0-preview.1.25120.3 | 108,486 | 2/25/2025 | |
| 9.0.11 | 50,465 | 11/11/2025 | |
| 9.0.10 | 997,277 | 10/14/2025 | |
| 9.0.9 | 1,673,718 | 9/9/2025 | |
| 9.0.8 | 1,678,625 | 8/5/2025 | |
| 9.0.7 | 1,285,315 | 7/8/2025 | |
| 9.0.6 | 1,582,778 | 6/10/2025 | |
| 9.0.5 | 2,358,356 | 5/13/2025 | |
| 9.0.4 | 2,399,291 | 4/8/2025 | |
| 9.0.3 | 1,856,028 | 3/11/2025 | |
| 9.0.2 | 1,999,034 | 2/11/2025 | |
| 9.0.1 | 1,721,754 | 1/14/2025 | |
| 9.0.0 | 3,978,945 | 11/12/2024 | |
| 9.0.0-rc.2.24474.3 | 65,175 | 10/8/2024 | |
| 9.0.0-rc.1.24452.1 | 43,576 | 9/10/2024 | |
| 9.0.0-preview.7.24406.2 | 9,942 | 8/13/2024 | |
| 9.0.0-preview.6.24328.4 | 12,819 | 7/9/2024 | |
| 9.0.0-preview.5.24306.11 | 5,167 | 6/11/2024 | |
| 9.0.0-preview.4.24267.6 | 3,214 | 5/21/2024 | |
| 9.0.0-preview.3.24172.13 | 70,592 | 4/11/2024 | |
| 9.0.0-preview.2.24128.4 | 4,584 | 3/12/2024 | |
| 9.0.0-preview.1.24081.5 | 27,933 | 2/13/2024 | |
| 8.0.22 | 49,585 | 11/11/2025 | |
| 8.0.21 | 608,399 | 10/14/2025 | |
| 8.0.20 | 1,001,348 | 9/9/2025 | |
| 8.0.19 | 1,663,310 | 8/4/2025 | |
| 8.0.18 | 898,909 | 7/8/2025 | |
| 8.0.17 | 1,469,511 | 6/10/2025 | |
| 8.0.16 | 1,383,982 | 5/13/2025 | |
| 8.0.15 | 2,179,313 | 4/8/2025 | |
| 8.0.14 | 2,226,724 | 3/11/2025 | |
| 8.0.13 | 2,572,271 | 2/11/2025 | |
| 8.0.12 | 2,426,235 | 1/14/2025 | |
| 8.0.11 | 6,824,528 | 11/12/2024 | |
| 8.0.10 | 8,960,258 | 10/8/2024 | |
| 8.0.8 | 10,181,953 | 8/13/2024 | |
| 8.0.7 | 7,223,995 | 7/9/2024 | |
| 8.0.6 | 6,738,420 | 5/28/2024 | |
| 8.0.5 | 2,605,889 | 5/14/2024 | |
| 8.0.4 | 6,808,178 | 4/9/2024 | |
| 8.0.3 | 4,360,613 | 3/12/2024 | |
| 8.0.2 | 4,194,502 | 2/13/2024 | |
| 8.0.1 | 4,712,950 | 1/9/2024 | |
| 8.0.0 | 8,216,219 | 11/14/2023 | |
| 8.0.0-rc.2.23480.2 | 65,712 | 10/10/2023 | |
| 8.0.0-rc.1.23421.29 | 71,132 | 9/12/2023 | |
| 8.0.0-preview.7.23375.9 | 13,693 | 8/8/2023 | |
| 8.0.0-preview.6.23329.11 | 44,273 | 7/11/2023 | |
| 8.0.0-preview.5.23302.2 | 12,987 | 6/13/2023 | |
| 8.0.0-preview.4.23260.4 | 265,075 | 5/16/2023 | |
| 8.0.0-preview.3.23177.8 | 3,604 | 4/11/2023 | |
| 8.0.0-preview.2.23153.2 | 1,935 | 3/14/2023 | |
| 8.0.0-preview.1.23112.2 | 41,643 | 2/21/2023 | |
| 7.0.20 | 680,788 | 5/28/2024 | |
| 7.0.19 | 120,801 | 5/14/2024 | |
| 7.0.18 | 253,454 | 4/9/2024 | |
| 7.0.17 | 489,093 | 3/12/2024 | |
| 7.0.16 | 504,163 | 2/13/2024 | |
| 7.0.15 | 704,503 | 1/9/2024 | |
| 7.0.14 | 1,141,432 | 11/14/2023 | |
| 7.0.13 | 2,425,374 | 10/24/2023 | |
| 7.0.12 | 1,133,079 | 10/10/2023 | |
| 7.0.11 | 3,662,209 | 9/12/2023 | |
| 7.0.10 | 1,884,520 | 8/8/2023 | |
| 7.0.9 | 1,433,230 | 7/11/2023 | |
| 7.0.8 | 1,176,500 | 6/22/2023 | |
| 7.0.7 | 608,036 | 6/13/2023 | |
| 7.0.5 | 4,039,639 | 4/11/2023 | |
| 7.0.4 | 2,113,449 | 3/14/2023 | |
| 7.0.3 | 1,880,856 | 2/14/2023 | |
| 7.0.2 | 1,932,177 | 1/10/2023 | |
| 7.0.1 | 1,139,424 | 12/13/2022 | |
| 7.0.0 | 3,937,791 | 11/7/2022 | |
| 7.0.0-rc.2.22476.2 | 71,054 | 10/11/2022 | |
| 7.0.0-rc.1.22427.2 | 23,766 | 9/14/2022 | |
| 7.0.0-preview.7.22376.6 | 10,965 | 8/9/2022 | |
| 7.0.0-preview.6.22330.3 | 4,139 | 7/12/2022 | |
| 7.0.0-preview.5.22303.8 | 9,765 | 6/14/2022 | |
| 7.0.0-preview.4.22251.1 | 2,414 | 5/10/2022 | |
| 7.0.0-preview.3.22178.4 | 1,437 | 4/13/2022 | |
| 7.0.0-preview.2.22153.2 | 1,211 | 3/14/2022 | |
| 7.0.0-preview.1.22109.13 | 5,249 | 2/17/2022 | |
| 6.0.36 | 1,616,798 | 11/12/2024 | |
| 6.0.35 | 329,397 | 10/8/2024 | |
| 6.0.33 | 1,382,675 | 8/13/2024 | |
| 6.0.32 | 429,362 | 7/9/2024 | |
| 6.0.31 | 646,282 | 5/28/2024 | |
| 6.0.30 | 224,528 | 5/14/2024 | |
| 6.0.29 | 900,405 | 4/9/2024 | |
| 6.0.28 | 551,740 | 3/12/2024 | |
| 6.0.27 | 1,031,313 | 2/13/2024 | |
| 6.0.26 | 1,220,489 | 1/9/2024 | |
| 6.0.25 | 2,061,033 | 11/14/2023 | |
| 6.0.24 | 1,018,609 | 10/24/2023 | |
| 6.0.23 | 723,532 | 10/10/2023 | |
| 6.0.22 | 1,208,585 | 9/12/2023 | |
| 6.0.21 | 1,831,097 | 8/8/2023 | |
| 6.0.20 | 1,634,529 | 7/11/2023 | |
| 6.0.19 | 1,026,948 | 6/22/2023 | |
| 6.0.18 | 679,841 | 6/13/2023 | |
| 6.0.16 | 3,493,678 | 4/11/2023 | |
| 6.0.15 | 2,136,620 | 3/14/2023 | |
| 6.0.14 | 2,454,383 | 2/14/2023 | |
| 6.0.13 | 3,296,054 | 1/10/2023 | |
| 6.0.12 | 2,996,110 | 12/13/2022 | |
| 6.0.11 | 3,998,695 | 11/7/2022 | |
| 6.0.10 | 5,608,510 | 10/11/2022 | |
| 6.0.9 | 4,317,038 | 9/13/2022 | |
| 6.0.8 | 5,110,254 | 8/9/2022 | |
| 6.0.7 | 4,504,024 | 7/12/2022 | |
| 6.0.6 | 3,444,651 | 6/14/2022 | |
| 6.0.5 | 4,357,541 | 5/10/2022 | |
| 6.0.4 | 4,057,535 | 4/11/2022 | |
| 6.0.3 | 4,768,628 | 3/8/2022 | |
| 6.0.2 | 3,947,769 | 2/8/2022 | |
| 6.0.1 | 5,913,589 | 12/14/2021 | |
| 6.0.0 | 7,146,966 | 11/8/2021 | |
| 6.0.0-rc.2.21480.10 | 210,118 | 10/12/2021 | |
| 6.0.0-rc.1.21452.15 | 177,696 | 9/14/2021 | |
| 6.0.0-preview.7.21378.6 | 9,291 | 8/10/2021 | |
| 6.0.0-preview.6.21355.2 | 5,462 | 7/14/2021 | |
| 6.0.0-preview.5.21301.17 | 3,781 | 6/15/2021 | |
| 6.0.0-preview.4.21253.5 | 6,949 | 5/24/2021 | |
| 6.0.0-preview.3.21201.13 | 5,205 | 4/8/2021 | |
| 6.0.0-preview.2.21154.6 | 1,239 | 3/11/2021 | |
| 6.0.0-preview.1.21103.6 | 1,620 | 2/12/2021 | |
| 5.0.17 | 1,016,406 | 5/10/2022 | |
| 5.0.16 | 193,002 | 4/11/2022 | |
| 5.0.15 | 309,477 | 3/8/2022 | |
| 5.0.14 | 293,123 | 2/8/2022 | |
| 5.0.13 | 721,799 | 12/14/2021 | |
| 5.0.12 | 846,002 | 11/7/2021 | |
| 5.0.11 | 1,500,703 | 10/12/2021 | |
| 5.0.10 | 1,524,717 | 9/14/2021 | |
| 5.0.9 | 1,622,528 | 8/10/2021 | |
| 5.0.8 | 1,286,371 | 7/13/2021 | |
| 5.0.7 | 1,721,762 | 6/8/2021 | |
| 5.0.6 | 1,384,203 | 5/11/2021 | |
| 5.0.5 | 1,954,261 | 4/6/2021 | |
| 5.0.4 | 1,130,115 | 3/9/2021 | |
| 5.0.3 | 1,349,552 | 2/9/2021 | |
| 5.0.2 | 1,348,820 | 1/12/2021 | |
| 5.0.1 | 942,239 | 12/8/2020 | |
| 5.0.0 | 2,366,573 | 11/9/2020 | |
| 5.0.0-rc.2.20475.17 | 18,167 | 10/13/2020 | |
| 5.0.0-rc.1.20451.17 | 185,263 | 9/14/2020 | |
| 5.0.0-preview.8.20414.8 | 9,608 | 8/25/2020 | |
| 5.0.0-preview.7.20365.19 | 4,671 | 7/21/2020 | |
| 5.0.0-preview.6.20312.15 | 2,343 | 6/25/2020 | |
| 5.0.0-preview.5.20279.2 | 1,180 | 6/10/2020 | |
| 5.0.0-preview.4.20257.10 | 1,832 | 5/18/2020 | |
| 5.0.0-preview.3.20215.14 | 2,327 | 4/23/2020 | |
| 5.0.0-preview.2.20167.3 | 1,117 | 4/2/2020 | |
| 5.0.0-preview.1.20124.5 | 1,332 | 3/16/2020 | |
| 3.1.32 | 788,676 | 12/13/2022 | |
| 3.1.31 | 192,357 | 11/8/2022 | |
| 3.1.30 | 734,896 | 10/11/2022 | |
| 3.1.29 | 141,670 | 9/13/2022 | |
| 3.1.28 | 191,132 | 8/9/2022 | |
| 3.1.27 | 204,494 | 7/12/2022 | |
| 3.1.26 | 195,946 | 6/14/2022 | |
| 3.1.25 | 260,190 | 5/10/2022 | |
| 3.1.24 | 224,454 | 4/11/2022 | |
| 3.1.23 | 390,420 | 3/8/2022 | |
| 3.1.22 | 992,743 | 12/14/2021 | |
| 3.1.21 | 789,800 | 11/7/2021 | |
| 3.1.20 | 699,088 | 10/11/2021 | |
| 3.1.19 | 493,453 | 9/14/2021 | |
| 3.1.18 | 1,084,943 | 8/10/2021 | |
| 3.1.17 | 884,461 | 7/13/2021 | |
| 3.1.16 | 795,410 | 6/8/2021 | |
| 3.1.15 | 794,725 | 5/11/2021 | |
| 3.1.14 | 1,777,296 | 4/6/2021 | |
| 3.1.13 | 1,285,048 | 3/9/2021 | |
| 3.1.12 | 1,012,095 | 2/9/2021 | |
| 3.1.11 | 1,217,428 | 1/12/2021 | |
| 3.1.10 | 3,088,382 | 11/9/2020 | |
| 3.1.9 | 3,269,109 | 10/13/2020 | |
| 3.1.8 | 3,292,911 | 9/8/2020 | |
| 3.1.7 | 2,523,113 | 8/11/2020 | |
| 3.1.6 | 2,464,745 | 7/14/2020 | |
| 3.1.5 | 3,794,345 | 6/9/2020 | |
| 3.1.4 | 2,343,046 | 5/12/2020 | |
| 3.1.3 | 3,922,012 | 3/24/2020 | |
| 3.1.2 | 2,928,194 | 2/18/2020 | |
| 3.1.1 | 3,293,296 | 1/14/2020 | |
| 3.1.0 | 3,426,638 | 12/3/2019 | |
| 3.1.0-preview3.19555.2 | 3,643 | 11/13/2019 | |
| 3.1.0-preview2.19528.8 | 1,328 | 11/1/2019 | |
| 3.1.0-preview1.19508.20 | 1,927 | 10/15/2019 | |
| 3.0.3 | 263,290 | 2/18/2020 | |
| 3.0.2 | 110,296 | 1/14/2020 | |
| 3.0.0 | 4,415,924 | 9/23/2019 | |
| 3.0.0-rc1.19457.4 | 15,981 | 9/16/2019 | |
| 3.0.0-preview9.19424.4 | 9,299 | 9/4/2019 | |
| 3.0.0-preview8.19405.7 | 38,417 | 8/13/2019 | |
| 3.0.0-preview7.19365.7 | 14,136 | 7/23/2019 | |
| 3.0.0-preview6.19307.2 | 7,463 | 6/12/2019 | |
| 3.0.0-preview5-19227-01 | 11,894 | 5/6/2019 | |
| 3.0.0-preview4-19216-03 | 2,491 | 4/18/2019 | |
| 3.0.0-preview3-19153-02 | 2,325 | 3/6/2019 | |
| 3.0.0-preview-19075-0444 | 7,683 | 1/29/2019 | |
| 3.0.0-preview-18579-0056 | 4,597 | 12/3/2018 | |
| 2.3.0 | 89,636 | 1/14/2025 | |
| 2.2.0 | 13,089,515 | 12/3/2018 | |
| 2.2.0-preview3-35497 | 23,926 | 10/17/2018 | |
| 2.2.0-preview2-35157 | 13,558 | 9/12/2018 | |
| 2.2.0-preview1-35029 | 14,176 | 8/22/2018 | |
| 2.1.1 | 7,448,278 | 6/18/2018 | |
| 2.1.0 | 1,665,901 | 5/29/2018 | |
| 2.1.0-rc1-final | 37,812 | 5/6/2018 | |
| 2.1.0-preview2-final | 13,713 | 4/10/2018 | |
| 2.1.0-preview1-final | 29,253 | 2/26/2018 | |
| 2.0.3 | 301,790 | 5/7/2018 | |
| 2.0.2 | 762,639 | 3/13/2018 | |
| 2.0.1 | 1,344,508 | 11/14/2017 | |
| 2.0.0 | 1,042,285 | 8/11/2017 | |
| 2.0.0-preview2-final | 10,526 | 6/28/2017 | |
| 2.0.0-preview1-final | 21,263 | 5/10/2017 | |
| 1.1.3 | 168,640 | 9/20/2017 | |
| 1.1.2 | 609,780 | 5/9/2017 | |
| 1.1.1 | 313,927 | 3/6/2017 | |
| 1.1.0 | 402,131 | 11/16/2016 | |
| 1.1.0-preview1-final | 6,152 | 10/24/2016 | |
| 1.0.5 | 57,005 | 11/14/2017 | |
| 1.0.4 | 37,020 | 9/20/2017 | |
| 1.0.3 | 89,691 | 5/9/2017 | |
| 1.0.2 | 200,005 | 3/6/2017 | |
| 1.0.1 | 46,993 | 12/12/2016 | |
| 1.0.0 | 337,142 | 6/27/2016 | |
| 1.0.0-rc2-final | 16,591 | 5/16/2016 |