running-unit-tests

Runs and filters MSBuild unit tests using xUnit v3 with Microsoft.Testing.Platform.

1.2k|337|Updated Oct 13, 2022
One-click install
npx skills add https://github.com/dotnet/dotnet --skill running-unit-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: running-unit-tests
Source: https://github.com/dotnet/dotnet/tree/main/src/msbuild/.github/skills/running-unit-tests
Command: npx skills add https://github.com/dotnet/dotnet --skill running-unit-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Running MSBuild unit tests efficiently is tricky because this repo uses xUnit v3 with the Microsoft.Testing.Platform (MTP) runner instead of VSTest, so many familiar dotnet test flags silently do nothing. This Skill guides you through fast scoped test loops during development and full validation passes before finalizing a change.

Core Features & Use Cases

  • Fast dev loop: Run a single test project with dotnet test <project> -f net11.0 -- --filter-method "*MyFeature*" or invoke the built test exe directly for sub-30-second iterations.
  • MTP vs VSTest flag guidance: Learn which flags apply (--report-trx, --coverage, --filter-method, --filter-trait) and which VSTest-only flags are ignored (--filter, --blame, --collect, --logger trx).
  • Final validation workflow: Run all TFMs per affected project, or the full repo suite via build.cmd -test / build.sh --test, with TRX report capture for CI or reporting.
  • Use Case: You modified code in src/Tasks/** and want quick feedback. Use this Skill to run only Microsoft.Build.Tasks.UnitTests.csproj filtered to your feature, then run the full Release validation before declaring the change done.

Quick Start

Ask the AI to run the MSBuild unit tests for the project matching your changed source area, filtered to your feature, using the fast scoped dotnet test loop.

Frequently Asked Questions about running-unit-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run a single MSBuild unit test by name?

Run dotnet test with the project path and pass --filter-method after the -- separator, for example dotnet test src\Tasks.UnitTests\Microsoft.Build.Tasks.UnitTests.csproj -- --filter-method "*MyTestMethod*". You can also run the built test exe directly with the same filter for faster iteration.

How do I filter xUnit v3 tests with dotnet test?

Use MTP-native filters like --filter-method, --filter-class, and --filter-trait after the -- separator. The VSTest-style --filter flag is ignored in this repo because test projects run on Microsoft.Testing.Platform, not VSTest.

Why is my dotnet test --filter or --logger trx flag not working?

Those flags are VSTest-only and silently ignored because this repo uses the Microsoft.Testing.Platform runner with xUnit v3. Use --report-trx instead of --logger trx, and --filter-method or --filter-trait instead of --filter.

Does dotnet test run MSBuild tests on multiple target frameworks?

Yes, test projects multi-target .NETFramework and .NETCoreApp on Windows, and dotnet test runs the suite once per TFM. Pass -f net11.0 to restrict to a single TFM and roughly halve runtime during iteration.

Why are MSBuild tests running single-threaded?

The repo's xunit.runner.json sets maxParallelThreads to 1 and disables test collection parallelization because many tests mutate process-global state like environment variables and the current directory. You can temporarily relax this during iteration, but expect flakes and revert before final validation.

When should I use build.cmd -test instead of dotnet test?

Use dotnet test for fast scoped iteration on a single project, and build.cmd -test or build.sh --test for final validation of broad changes. The build script runs the full repo test suite through the Arcade harness and takes about nine minutes.