用途:本技能用于在 dotnet/msbuild 仓库中高效运行、筛选和加速单元测试,并在提交改动前完成最终验证。
主要能力:仓库使用 xUnit v3 与 Microsoft.Testing.Platform(MTP)运行器,测试项目以 OutputType=Exe 构建,每个测试程序集是独立宿主进程。提供两种运行方式:开发循环用 dotnet test <project> 运行单个项目并可筛选;最终验证用 build.cmd -test 或 build.sh --test 通过 Arcade 构建并运行全部测试项目。
使用方式:快速迭代示例:dotnet test src\Tasks.UnitTests\Microsoft.Build.Tasks.UnitTests.csproj -f net10.0 -- --filter-method "MyFeature";也可直接运行测试 exe:artifacts\bin\Microsoft.Build.Tasks.UnitTests\Debug\net10.0\Microsoft.Build.Tasks.UnitTests.exe --filter-method "MyFeature" --no-progress。最终验证运行 dotnet test <proj> -c Release(全部 TFM),大范围改动运行 .\build.cmd -test -c Release 或 ./build.sh --test -c Release。生成 TRX 用 --report-trx --report-trx-filename validation.trx --results-directory artifacts\TestResults。
仓库特定配置:测试项目在 Windows 上多目标 net472 与 net10.0,Linux/macOS 仅 net10.0;xunit.runner.json 默认 maxParallelThreads: 1 且 parallelizeTestCollections: false;通过 --filter-not-trait Category=... 自动过滤平台不适用测试;非 Windows 上无条件追加 --coverage --coverage-settings Coverage.config,无 MSBuild 属性可关闭,需直接运行 exe 跳过。
限制与注意:MTP 下 --logger trx、--collect、--filter、--blame、--settings、--diag 等 VSTest 参数会被忽略,应使用 --report-trx、--coverage、--filter-method/--filter-class/--filter-trait。加速手段(单 TFM、放宽并行、-p:CreateBootstrap=false)仅用于迭代,最终验证前需还原。切换 TFM 不重新构建会运行旧二进制。查看摘要时需关注 skipped 数量变化。按改动源码区域选择对应 *.UnitTests 项目。