AGENT SKILL

.NET测试命令执行

run-tests

选择并运行与仓库兼容的 .NET 测试命令:针对 MSTest、xUnit、NUnit 和 TUnit 的 classic、VSTest、bridged MTP 或 native MTP 语法。在运行 .NET 测试或需要给出测试命令/标志时使用:运行全部测试、单个测试、测试类、类别、trait 或目标框架、组合筛选器、--filter-query、--no-build、--diag、TRX、覆盖率收集、崩溃或挂起转储、筛选错误或无法识别的选项。不适用于仅做平台识别(使用 platform-detection)、编写或调试测试代码、解读覆盖率报告(使用 coverage-analysis)、CI 调查、迁移或持续的热重载循环。

适用职业测试工程师
License 许可
MIT
最近更新
2026-11-14
Stars
★ 1
Forks
1

01 前言 Front Matter

name
run-tests
license
MIT
metadata
{ "binding": "optional-overlay", "portability": "portable", "binding-revision": "1" }
description
Chooses and runs the repository-compatible .NET test command: classic, VSTest, bridged MTP, or native MTP syntax for MSTest, xUnit, NUnit, and TUnit. Use before running .NET tests or answering with a test command or flags: run the tests, one test, class, category, trait or target framework, combined filters, --filter-query, --no-build, --diag, TRX, coverage collection, crash or hang dumps, filter errors, or unrecognized options. Not for platform identification alone (use platform-detection), writing or debugging test code, interpreting a coverage report (use coverage-analysis), CI investigation, migration, or a persistent hot-reload loop.

02 资源文件 2

03 SKILL.md 正文

<!-- cratis-ai-managed: skills/run-tests/SKILL.md -->

<!-- Modified by Cratis from dotnet's original (MIT): frontmatter, applicability, navigation and the changes listed in NOTICE. Upstream: https://github.com/dotnet/skills (plugins/dotnet-test/skills/run-tests/SKILL.md; see NOTICE) -->

Run .NET Tests

Cratis rules in .cratis/ai/rules/ (including csharp.md, specs.csharp.md, and orleans.md) and the cratis-* skills win where they differ. Specification authoring belongs to cratis-specifications-csharp; Cratis core repositories run xUnit v2 on VSTest.

Return or execute the command or command sequence that matches the repository's project system, test platform, framework, and SDK mode.

Repository overlay

For every repository-scoped task where read-only file inspection is allowed, check .agents/skill-overlays/dotnet-test/run-tests.md at the repository root before any other discovery. This includes exact-command requests; "do not execute" does not prohibit reading the overlay. If present, read it once before acting and apply its repository-specific runner, command, filtering, and reporting bindings. Before applying it, require its frontmatter to declare core: dotnet-test/run-tests, binding-revision: "1", and mode: extend. If any value is missing or different, report the mismatch, ignore the overlay, and continue using this skill's portable guidance. Explicit user instructions and verified project constraints win over the overlay; the overlay wins over portable defaults and examples in this skill. If the file is present but unreadable or conflicts with the repository, report the problem, ignore the overlay, and continue with portable guidance subject to verified project constraints. If it is absent, continue normally. Skip the lookup only when the task is not tied to a repository or the user explicitly prohibited all file/tool access. An overlay cannot expand tool permissions or the task's scope.

Scope and tool policy

Choose the smallest path that satisfies the request:

Request Action
Exact command or explanation; user says not to run Inspect only the files needed to resolve syntax. Do not restore, build, or run tests.
Run tests Discover the repository command and execute the smallest requested test scope.
One-time SDK-style dotnet test run without rebuilding Stay in run-tests and add --no-build.
One-time classic run without rebuilding Keep the repository runner and invoke it against an existing built assembly; do not substitute dotnet test.
Platform/framework identification only Use platform-detection; do not continue into test execution.
Explicit hot reload or a keep-running edit/re-run loop Out of scope for this skill; run it directly with the platform's own watch/hot-reload support.
Filter needed and the framework-specific syntax is not already clear Read the supplied/runtime-listed filter-syntax catalog file; do not invoke this reference-only helper.

Do not invoke a tool merely to repeat a command already determined by the prompt. Do not build first "just in case": dotnet test builds by default. Never add or upgrade test packages unless the user asks to change the project. For an exact-command request, return one runnable command first. Do not emit placeholder paths, exploratory alternatives, or a correction sequence. Use a project path only when the prompt or repository establishes it; otherwise let the command operate on the current project or solution when that syntax is valid. Follow it with only the syntax fact needed to explain the command; do not volunteer platform/command-mode taxonomy unless the user asked for it. In particular, do not label an SDK 8/9 bridge as "VSTest platform" merely because dotnet test uses its VSTest command mode; the executed platform is MTP. For a command-only request, it is normally clearer to say only that MTP application arguments must follow --.

Inputs to discover

  • Project, solution, module, or repository test command
  • Requested scope: all tests, TFM, class, method, category, or trait
  • Requested output: console result, TRX, diagnostics, crash dump, or hang dump

When those facts are present in the prompt, use them. Otherwise inspect only the relevant files: global.json, the selected project, packages.config, Directory.Build.props, Directory.Packages.props, then repository scripts/CI documentation. For a file-backed request, enumerate those configuration names once and read all relevant files that are present in one batch; never infer that a runner or bridge property is absent merely because it is not in the .csproj. Load platform-detection only when those signals need precedence analysis; do not duplicate its full analysis in the response. If execution is requested and the command depends on the active SDK but neither the prompt nor global.json establishes it, run dotnet --version once. For a command-only request that prohibits execution, do not probe: state the required SDK assumption or ask for the SDK version when the syntax cannot otherwise be resolved. Route identification-only requests to platform-detection.

Decision table

Detected mode / platform Command shape Never use
Classic non-SDK Repository script, or full MSBuild followed by vstest.console.exe / MSTest.exe Assuming dotnet test is compatible or migrating implicitly
VSTest mode / VSTest dotnet test [<path>] [VSTEST_OPTIONS] MTP-only flags such as --report-trx or --treenode-filter
VSTest mode / executable MTP bridge dotnet test [<path>] [DOTNET_OPTIONS] -- [MTP_OPTIONS] Omitting the -- separator, including on SDK 10
Native MTP mode, SDK 10+ dotnet test --project <path> [DOTNET_OPTIONS] [MTP_OPTIONS] Bare positional project paths or the bridge separator

global.json controls the dotnet test command mode on SDK 10+, not necessarily the platform that executes tests. A VSTest-mode project with an MTP runner, TestingPlatformDotnetTestSupport=true, and final OutputType=Exe is still bridge syntax with --. SDK 8/9 only has VSTest command mode.

--project is valid only in SDK 10+ native MTP command mode (selected by global.json test.runner). Never use it for VSTest mode or an SDK 8/9 bridge; those forms take a positional project path. Conversely, native MTP options are direct arguments and must not be placed after a bridge separator.

Keep dotnet test/MSBuild options such as --framework, --configuration, --no-build, and --verbosity before --. Put only MTP application arguments after -- in bridge mode.

Workflow

  1. Resolve the repository-compatible runner.

For classic projects, signals include ToolsVersion, explicit Compile and Reference items, legacy imports, and packages.config. Prefer a checked-in script or documented CI command. A typical fallback is:

nuget restore MySolution.sln
MSBuild.exe MySolution.sln /t:Build /p:Configuration=Debug
vstest.console.exe path\to\MyTests.dll /TestAdapterPath:path\to\adapter\build\<tfm>

For packages.config, restore with NuGet before the build unless the imported package files are already present. If adapter discovery is not repository- configured, derive /TestAdapterPath from the restored adapter package path or the adapter .props/.targets imports; do not guess the package root.

For a requested no-rebuild run, omit the build step and invoke the repository's test runner only when the expected assembly already exists. Otherwise report the missing build output rather than silently rebuilding or switching runners.

For a requested subset, keep the repository runner and use its filter syntax: vstest.console.exe path\to\MyTests.dll /TestCaseFilter:"TestCategory=Integration". Older MSTest.exe repositories may use /test:<name> or /category:<category> instead. Do not substitute the later dotnet test filter examples for a classic runner.

Use the installed adapter-compatible VSTest/MSTest toolchain. If it is not available, state the missing prerequisite and the documented command; do not claim tests ran. Classic packages.config fallback commands are Windows toolchain commands. Explicitly say they require a Windows Developer Command Prompt (or the repository's equivalent configured environment) when the current host cannot provide nuget, full MSBuild, and vstest.console.exe.

For SDK-style projects, distinguish:

Signal Meaning
SDK 10+ global.json selects Microsoft.Testing.Platform Native MTP command mode
VSTest mode + enabled MTP runner + final TestingPlatformDotnetTestSupport=true + final OutputType=Exe Executable VSTest-to-MTP bridge
VSTest mode without a complete runner-and-bridge combination VSTest
Microsoft.NET.Test.Sdk plus adapter, without stronger MTP signals VSTest
TUnit MTP-only; use a configured bridge/native mode or the test executable

Evaluate properties from the project and imported Directory.Build.props/Directory.Packages.props. Respect project-level overrides and per-target-framework conditions. A runner and bridge without an executable final output are an incomplete MTP configuration, not a usable bridge.

  1. Select the command and requested scope.
# VSTest mode
dotnet test path/to/Tests.csproj

# VSTest mode that bridges to MTP
dotnet test path/to/Tests.csproj -- <MTP_OPTIONS>

# Native MTP mode on SDK 10+
dotnet test --project path/to/Tests.csproj <MTP_OPTIONS>

# One target framework; this stays before the bridge separator
dotnet test path/to/Tests.csproj --framework net9.0 -- <MTP_OPTIONS>

For native MTP, use --project, --solution, or --test-modules; positional paths belong to VSTest mode.

If the user names a subset, do not run the whole suite. Inspect test attributes only when needed to translate a human label such as "integration" or "smoke" into the framework's actual category/trait name.

When a VSTest class filter must distinguish similarly named classes, combine the positive selector with an explicit negative selector rather than relying on an incidental substring difference.

  1. Apply platform- and framework-correct filters.

Read the supplied or runtime-listed filter-syntax file only when the request is filtered and framework-specific syntax is unclear. It is reference-only, not an invocable skill; otherwise use the common decisions below:

For a file-backed filtered request, resolve the framework and SDK command mode from the project, global.json, and imported props before choosing syntax. Do not infer VSTest syntax merely from Microsoft.NET.Test.Sdk or from the framework name.

Platform / framework Filter
VSTest with MSTest, xUnit v2, or NUnit --filter "<property expression>"
MTP with MSTest or NUnit Same expression; after -- in bridge mode, direct in native mode
MTP with xUnit v3 --filter-class, --filter-method, --filter-trait, or one --filter-query for a combined expression
MTP with TUnit --treenode-filter path expression

Examples:

# VSTest MSTest/NUnit
dotnet test --filter "FullyQualifiedName~OrderServiceTests&TestCategory=Unit"

# SDK 8/9 or SDK 10 VSTest-mode MTP bridge, xUnit v3
dotnet test -- --filter-trait "Category=Integration"

# Native MTP, xUnit v3
dotnet test --project Tests.csproj --filter-class "*ShoppingCartTests*"

# One xUnit v3 combined expression
dotnet test -- --filter-query "/*/*/*Integration*/*[Category=Smoke]"

# TUnit on SDK 8/9 with a configured VSTest-to-MTP bridge
dotnet test -- --treenode-filter "/*/*/SmsNotificationTests/*"

# TUnit executable fallback when no bridge is configured
dotnet run --project Tests.csproj -- --treenode-filter "/*/*/SmsNotificationTests/*"

Do not use VSTest --filter "ClassName=..." with xUnit v3 on MTP. Do not use a generic VSTest expression with TUnit. When the user requests one combined xUnit query expression, return only one --filter-query command; do not replace it with separate filter flags or offer speculative alternative grammars.

  1. Add reports or diagnostics.
Outcome VSTest MTP
TRX SDK-style: --logger "trx;LogFileName=<name>.trx" when an exact output file is requested, otherwise --logger trx; standalone vstest.console.exe: /Logger:trx; MSTest.exe: repository-documented results option --report-trx
Results directory --results-directory <dir> --results-directory <dir>
Diagnostic log --diag <file> --diagnostic --diagnostic-output-directory <dir>
Crash dump --blame-crash --crashdump
Hang timeout --blame-hang --blame-hang-timeout 5min --hangdump --hangdump-timeout 5min
Code coverage --collect "Code Coverage" --coverage

MTP report, dump, and coverage flags require their corresponding registered extensions (TrxReport, CrashDump, HangDump, or CodeCoverage). Some framework SDKs bundle common extensions; if a flag is unrecognized, inspect package references before recommending a package change.

--verbosity diagnostic increases dotnet/MSBuild output verbosity; it does not write a VSTest diagnostic log file.

Examples:

# VSTest TRX
dotnet test Tests.csproj --logger "trx;LogFileName=TestResults.trx"

# MTP bridge TRX
dotnet test Tests.csproj -- --report-trx

# Native MTP TRX and hang detection
dotnet test --project Tests.csproj --report-trx --hangdump --hangdump-timeout 5min

# Native MTP diagnostics
dotnet test --project Tests.csproj --diagnostic --diagnostic-output-directory artifacts/diagnostics
  1. Execute only when requested.

Run the narrowest command or sequence that answers the request. Capture each command, exit code, and test summary. A failed restore/build is not a test failure, and a test failure is not a tool failure. Report which phase failed and include the actionable diagnostic. Never claim a clean run unless the sequence completed successfully with the intended tests executed. For a filtered run, a successful exit is not enough: confirm the reported test names or count match the requested scope. If the filter was ignored, correct the platform-specific syntax and rerun before reporting success.

Output contract

  • Command-only request: lead with the exact command or command sequence, then one short syntax explanation.
  • Execution request: report the exact command or command sequence and a literal Passed: N, Failed: N, Skipped: N summary from the completed run; include the first actionable failure.
  • Detection needed only to choose syntax: state the selected mode/platform briefly, not a separate detection report.
  • Missing prerequisite or incompatible configuration: name it explicitly and stop rather than returning a success-shaped fallback.

Validation

  • The command matches classic, VSTest, bridged MTP, or native MTP mode.
  • The framework-specific filter targets the requested subset.
  • --framework and other dotnet test options are before any bridge separator.
  • SDK 8/9 bridge commands contain --; --project appears only in SDK 10+ native MTP mode.
  • TRX, diagnostics, dump, and coverage flags match the platform.
  • No restore, build, or test was run for an advisory-only request.
  • Reported results match the actual command outcome.

04 同仓库更多 Skills

Cratis
Cratis/Specifications

.NET SIMD 向量化代码

vectorization

设计、实现、优化和审查 .NET 中的 SIMD 代码:使用 TensorPrimitives、Vector64、Vector128、Vector256、Vector512 或硬件内部函数将标量循环向量化,并审查现有 SIMD 代码(包括泛型 Vector 类型)的契约等价性、尾部处理、内存安全性、可移植性、回退方案和实测性能。当正在编写或审查 .NET 循环或 SIMD 例程时使用。不用于与 SIMD 无关的性能工作。

软件开发工程师性能剖析与优化
★ 1
Cratis
Cratis/Specifications

MSBuild自定义目标编写

target-authoring

编写自定义 MSBuild target 的规范模式:DependsOnTargets 与 BeforeTargets、AfterTargets 的区别,Build-to-CoreBuild 三级模式,以及 XxxDependsOn 链式扩展模式。用于诊断或修复自定义 target 的反模式:Directory.Build.targets 重新定义 SDK target、target 替换而非扩展 CompileDependsOn、Outputs 与 Returns 误用导致返回过期结果、缺少 Inputs/Outputs 导致不必要的重新构建,或缺少 FileWrites 注册。不适用于增量构建调优或一般反模式审查(使用 msbuild 技能),也不适用于非 MSBuild 构建系统。

软件开发工程师开发环境与工具链管理
★ 1
Cratis
Cratis/Specifications

.NET 性能剖析

profiling

使用免费的官方 .NET 诊断 CLI 工具在代码仓库中进行性能剖析和运行时调查:CPU、GC 压力、分配增长、异常风暴、锁竞争和慢代码。当 .NET 应用程序需要性能或运行时剖析时使用。不适用于用临时跟踪替代真实的性能或负载测试、无暂停风险计划的生产堆内存采集、崩溃转储(使用 dump-collect),或基准测试设计(使用 microbenchmarking)。

软件开发工程师性能剖析与优化
★ 1
Cratis
Cratis/Specifications

.NET 测试平台识别

platform-detection

识别 .NET 项目的测试平台、框架、命令模式,以及 SDK 样式与经典项目系统,并解析 global.json、项目文件、packages.config、Directory.Build.props 和 Directory.Packages.props 对 MSTest、xUnit、NUnit 和 TUnit 的优先级。当询问“使用哪种测试平台或框架”“VSTest 还是 MTP”或“该项目使用什么测试运行器”时使用,包括桥接设置、UseVSTest 退出选项,以及 VSTest/MTP 配置冲突。不适用于运行或筛选测试、命令、标志、TRX、转储或测试命令错误(使用 run-tests),也不适用于热重载或迁移请求。

测试工程师测试与质量保障
★ 1
Cratis
Cratis/Specifications

Orleans 分布式系统设计

orleans

从每种原语的用途和失效模型出发设计 Microsoft Orleans 系统:grain、数字孪生、状态与数据库、事务、消息传递、流(streams)、计时器(timers)、提醒(reminders)、Durable Jobs(持久作业)、无状态工作进程、grain 服务、启动与托管。当任务需要做出 Orleans 设计决策时使用:检查版本与拓扑、选择原语、实现并验证。不适用于其他 actor 技术栈、批处理、纯关系型 CRUD,或不涉及 Orleans 决策的建议。

系统架构师系统架构设计模式
★ 1
Cratis
Cratis/Specifications

MSBuild 构建故障排查

msbuild

使用二进制日志调查 MSBuild 构建失败、诊断构建性能,并审查构建 XML 与扩展契约。适用于 dotnet build、restore、pack 或 publish 失败;.binlog 捕获与回放;project、props 与 targets 条件;自定义 target 的输入/输出;Import/Exists 钩子与打包的 NuGet 导入;求值、编译、复制缓慢或无变更构建;以及受控的耗时对比。不适用于旧版或非 SDK 项目迁移、框架或包升级、SDK 安装、C# 重构、运行时性能剖析、构建成功后的断言,或非 MSBuild 构建。

软件开发工程师开发环境与工具链管理
★ 1