SuperAPI AI 工具集

dotnet-add-testing

测试与质量

查看项目

更新于 10-16 07:23

技能介绍

用途:为已有 .NET 项目搭建测试基础设施,包括创建 xUnit 测试项目、配置 coverlet 代码覆盖率,以及建立约定目录结构(tests/ 镜像 src/)。

主要能力:创建 xUnit 测试项目并加入解决方案、添加对被测项目的引用;按 .UnitTests、.IntegrationTests、*.FunctionalTests 命名约定组织测试;通过 tests/Directory.Build.props 设置测试专用构建属性;在 CPM 的 Directory.Packages.props 中登记测试包版本;配置覆盖率收集与阈值;为测试添加 .editorconfig 放宽规则;生成起始测试。

使用方式:先运行 dotnet-version-detection 确定 SDK 版本与 TFM,再运行 dotnet-project-analysis 了解现有解决方案结构。创建项目示例:dotnet new xunit -n MyApp.Core.UnitTests -o tests/MyApp.Core.UnitTests,随后 dotnet sln add 与 dotnet add ... reference。覆盖率收集:dotnet test --collect:"XPlat Code Coverage",结果位于 TestResults/*/coverage.cobertura.xml;阈值检查用 coverlet.msbuild 配合 /p:CollectCoverage=true /p:Threshold=80 /p:ThresholdType=line;HTML 报告用 dotnet tool install -g dotnet-reportgenerator-globaltool 后运行 reportgenerator。验证步骤:dotnet restore、dotnet build --no-restore、dotnet test --no-build。

适用场景:需要为 .NET 解决方案补充单元测试、集成测试脚手架与覆盖率配置的项目。

限制:不涵盖深入测试模式(xUnit v3、WebApplicationFactory、UI 测试),这些见 dotnet-testing-strategy 等技能;集成测试深度见 dotnet-integration-testing。资料未提供收费、价格或平台信息。