Dotnet-skills run-tests
git clone https://github.com/managedcode/dotnet-skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/managedcode/dotnet-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/catalog/Testing/Official-DotNet-Test/skills/run-tests" ~/.claude/skills/managedcode-dotnet-skills-run-tests && rm -rf "$T"
catalog/Testing/Official-DotNet-Test/skills/run-tests/SKILL.mdRun .NET Tests
Detect the test platform and framework, run tests, and apply filters using
dotnet test.
When to Use
- User wants to run tests in a .NET project
- User needs to run a subset of tests using filters
- User needs help detecting which test platform (VSTest vs MTP) or framework is in use
- User wants to understand the correct filter syntax for their setup
When Not to Use
- User needs to write or generate test code (use
for MSTest, or general coding assistance for other frameworks)writing-mstest-tests - User needs to migrate from VSTest to MTP (use
)migrate-vstest-to-mtp - User wants to iterate on failing tests without rebuilding (use
)mtp-hot-reload - User needs CI/CD pipeline configuration (use CI-specific skills)
- User needs to debug a test (use debugging skills)
Inputs
| Input | Required | Description |
|---|---|---|
| Project or solution path | No | Path to the test project (.csproj) or solution (.sln). Defaults to current directory. |
| Filter expression | No | Filter expression to select specific tests |
| Target framework | No | Target framework moniker to run against (e.g., ) |
Workflow
Quick Reference
| Platform | SDK | Command pattern |
|---|---|---|
| VSTest | Any | |
| MTP | 8 or 9 | |
| MTP | 10+ | |
Detection files to always check (in order):
global.json -> .csproj -> Directory.Build.props -> Directory.Packages.props
Step 1: Detect the test platform and framework
- Read
first — on .NET SDK 10+,global.json
is the authoritative MTP signal. If present, the project uses MTP and SDK 10+ syntax (no"test": { "runner": "Microsoft.Testing.Platform" }
separator).-- - Read
,.csproj
, andDirectory.Build.props
for framework packages and MTP properties.Directory.Packages.props - For full detection logic (SDK 8/9 signals, framework identification), see the
skill.platform-detection
Quick detection summary:
| Signal | Means |
|---|---|
has | MTP on SDK 10+ — pass args directly, no |
in csproj or Directory.Build.props | MTP on SDK 8/9 — pass args after |
| Neither signal present | VSTest |
Step 2: Run tests
VSTest (any .NET SDK version)
dotnet test [<PROJECT> | <SOLUTION> | <DIRECTORY> | <DLL> | <EXE>]
Common flags:
| Flag | Description |
|---|---|
| Target a specific framework in multi-TFM projects (e.g., ) |
| Skip build, use previously built output |
| Run selected tests (see Step 3) |
| Generate TRX results file |
| Collect code coverage using Microsoft Code Coverage (built-in, always available) |
| Enable blame mode to detect tests that crash the host |
| Collect a crash dump when the test host crashes |
| Abort test if it hangs longer than duration (e.g., ) |
| Verbosity: , , , , |
MTP with .NET SDK 8 or 9
With
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>, dotnet test bridges to MTP but uses VSTest-style argument parsing. MTP-specific arguments must be passed after --:
dotnet test [<PROJECT> | <SOLUTION> | <DIRECTORY> | <DLL> | <EXE>] -- <MTP_ARGUMENTS>
MTP with .NET SDK 10+
With the
global.json runner set to Microsoft.Testing.Platform, dotnet test natively understands MTP arguments without --:
dotnet test [--project <PROJECT_OR_DIRECTORY>] [--solution <SOLUTION_OR_DIRECTORY>] [--test-modules <EXPRESSION>] [<MTP_ARGUMENTS>]
Examples:
# Run all tests in a project dotnet test --project path/to/MyTests.csproj # Run all tests in a directory containing a project dotnet test --project path/to/ # Run all tests in a solution (sln, slnf, slnx) dotnet test --solution path/to/MySolution.sln # Run all tests in a directory containing a solution dotnet test --solution path/to/ # Run with MTP flags dotnet test --project path/to/MyTests.csproj --report-trx --blame-hang-timeout 5min
Note: The .NET 10+
syntax does not accept a bare positional argument like the VSTest syntax. Usedotnet test,--project, or--solutionto specify the target.--test-modules
Common MTP flags
These flags apply to MTP on both SDK versions. On SDK 8/9, pass after
--; on SDK 10+, pass directly.
Built-in flags (always available):
| Flag | Description |
|---|---|
| Skip build, use previously built output |
| Target a specific framework in multi-TFM projects |
| Directory for test result output |
| Enable diagnostic logging for the test platform |
| Directory for diagnostic log output |
Extension-dependent flags (require the corresponding extension package to be registered):
| Flag | Requires | Description |
|---|---|---|
| Framework-specific (not all frameworks support this) | Run selected tests (see Step 3) |
| | Generate TRX results file |
| | Set TRX output filename |
| | Abort test if it hangs longer than duration (e.g., ) |
| | Collect a crash dump when the test host crashes |
| | Collect code coverage using Microsoft Code Coverage |
Some frameworks (e.g., MSTest) bundle common extensions by default. Others may require explicit package references. If a flag is not recognized, check that the corresponding extension package is referenced in the project.
Alternative MTP invocations
MTP test projects are standalone executables. Beyond
dotnet test, they can be run directly:
# Build and run dotnet run --project <PROJECT_PATH> # Run a previously built DLL dotnet exec <PATH_TO_DLL> # Run the executable directly (Windows) <PATH_TO_EXE>
These alternative invocations accept MTP command line arguments directly (no
-- separator needed).
Step 3: Run filtered tests
See the
filter-syntax skill for the complete filter syntax for each platform and framework combination. Key points:
- VSTest (MSTest, xUnit v2, NUnit):
withdotnet test --filter <EXPRESSION>
,=
,!=
,~
operators!~ - MTP -- MSTest and NUnit: Same
syntax as VSTest; pass after--filter
on SDK 8/9, directly on SDK 10+-- - MTP -- xUnit v3: Uses
,--filter-class
,--filter-method
(not VSTest expression syntax)--filter-trait - MTP -- TUnit: Uses
with path-based syntax--treenode-filter
Validation
- Test platform (VSTest or MTP) was correctly identified
- Test framework (MSTest, xUnit, NUnit, TUnit) was correctly identified
- Correct
invocation was used for the detected platform and SDK versiondotnet test - Filter expressions used the syntax appropriate for the platform and framework
- Test results were clearly reported to the user
Common Pitfalls
| Pitfall | Solution |
|---|---|
Missing in a VSTest project | Tests won't be discovered. Add |
Using VSTest syntax with xUnit v3 on MTP | xUnit v3 on MTP uses , , etc. -- not the VSTest expression syntax |
Passing MTP args without on .NET SDK 8/9 | Before .NET 10, MTP args must go after : |
Using for MTP args on .NET SDK 10+ | On .NET 10+, MTP args are passed directly: — do NOT use |
| Multi-TFM project runs tests for all frameworks | Use to target a specific framework |
runner setting ignored | Requires .NET 10+ SDK. On older SDKs, use MSBuild property instead |
TUnit not recognized | TUnit is MTP-only. On .NET SDK 10+ use ; on older SDKs use since VSTest-mode does not support TUnit |