SuperAPI AI 工具集

dotnet-test

测试与质量

查看项目

更新于 10-15 21:12

技能介绍

用途:整理 .NET 项目运行测试、分析测试失败与配置测试选项的模式与诊断方法。

主要能力: 基础执行:dotnet test 运行整个解决方案;dotnet test tests/MyApp.Tests/MyApp.Tests.csproj 指定项目;--no-build、--no-restore 跳过构建或还原以加快执行。 测试筛选:--filter 支持 FullyQualifiedName、Name、DisplayName、ClassName 等属性,以及 Category 等 trait;运算符含 &(与)、|(或)、!(非)、~(包含)、=(等于),可组合复杂条件。 输出与日志:--verbosity quiet/normal/detailed/diagnostic(缩写 -v q 等);--logger 支持 console、trx、junit、html,可同时指定多个;--results-directory 指定结果目录。 代码覆盖率:--collect:"XPlat Code Coverage",或 Coverlet 的 /p:CollectCoverage=true,配合 CoverletOutputFormat 设置 cobertura、opencover 等格式;/p:Threshold 设置失败阈值,ThresholdType 指定按行等类型;可用 dotnet tool install -g dotnet-reportgenerator-globaltool 安装报告生成器,再用 reportgenerator 生成 HTML。 并行与超时:--parallel 控制并行,RunConfiguration.MaxCpuCount 限制工作进程,DisableParallelization 关闭并行;RunConfiguration.TestSessionTimeout 设置会话超时;xUnit 用 Fact(Timeout)、NUnit 用 Test, Timeout 设置单测试超时。 配置文件:runsettings 可配置 MaxCpuCount、ResultsDirectory、TestSessionTimeout 及 Code Coverage 数据收集器,通过 dotnet test --settings test.runsettings 使用。 失败分析与调试:列出常见失败模式(断言失败、NullReferenceException、TimeoutException、ObjectDisposedException、InvalidOperationException)及对应排查方向;用 -v d 获取详细输出,--blame 捕获挂起,--blame-hang 配合 --blame-hang-timeout 检测挂起。监视模式:dotnet watch test,可按项目或过滤器使用。 CI/CD:退出码 0 全部通过、1 测试失败、2 命令行错误;给出 Azure DevOps 与 GitHub Actions 的 dotnet test 示例。

限制:资料未提供具体版本要求、各框架全部兼容性细节、价格或收费信息。