migrate-xunit-to-mstest

Convert .NET test projects from xUnit v2/v3 to MSTest v4 while preserving test platform and parity.

5.3k|403|Updated Feb 3, 2026
One-click install
npx skills add https://github.com/dotnet/skills --skill migrate-xunit-to-mstest
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrate-xunit-to-mstest
Source: https://github.com/dotnet/skills/tree/main/plugins/dotnet-test-migration/skills/migrate-xunit-to-mstest
Command: npx skills add https://github.com/dotnet/skills --skill migrate-xunit-to-mstest

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Migrating .NET test suites from xUnit to MSTest by hand is error-prone: assertion semantics invert between frameworks, fixture lifetimes differ, and parallelization defaults change. This Skill performs the conversion systematically while preserving the target framework, test platform (VSTest or MTP), and test result parity.

Core Features & Use Cases

  • Mechanical conversion: Rewrites Fact/Theory/InlineData/MemberData to TestMethod/DataRow/DynamicData, maps traits and Owner, and swaps xUnit packages for the MSTest v4 metapackage or MSTest.Sdk.
  • Semantic mapping: Handles high-risk constructs such as exact-vs-derived exception assertions, IClassFixture/ICollectionFixture lifetime, ITestOutputHelper to TestContext, cancellation tokens, and xUnit parallelization defaults.
  • Parity verification: Builds, runs dotnet test, and compares discovered/passed/failed/skipped counts against the baseline, flagging constructs with no MSTest equivalent for manual follow-up.
  • Use Case: A team standardizing on MSTest v4 points the agent at an xUnit v3 test project; the Skill converts packages, attributes, assertions, and fixtures, then proves identical test counts without changing the target framework.

Quick Start

Convert the xUnit test project in the current workspace to MSTest v4, keeping the existing test platform, then build and run the tests to verify parity.

Frequently Asked Questions about migrate-xunit-to-mstest

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

FAQPage Schema
How do I convert xUnit tests to MSTest in .NET?

Replace xUnit packages with the MSTest v4 metapackage or MSTest.Sdk, map Fact/Theory to TestMethod, InlineData to DataRow, and MemberData to DynamicData. Then rewrite assertions, fixtures, and output helpers, and run dotnet test to confirm matching test counts.

What is the MSTest equivalent of xUnit Assert.Throws?

xUnit Assert.Throws<T> is exact-type and maps to MSTest Assert.ThrowsExactly<T>, while xUnit Assert.ThrowsAny<T> permits derived types and maps to MSTest Assert.Throws<T>. The names invert between the two frameworks, so swapping them directly changes behavior.

Does MSTest v4 support my target framework when migrating from xUnit?

MSTest v4 requires .NET 8 or later, or .NET Framework 4.6.2 or later, for test applications. Projects on older frameworks must first upgrade the target framework or use MSTest v3 as an intermediate target.

How do I migrate xUnit IClassFixture to MSTest?

Map IClassFixture<T> to a static fixture field created once by a static ClassInitialize method accepting TestContext and disposed in ClassCleanup. Using TestInitialize instead would create one fixture per test method, breaking the shared-instance semantics.

Can I keep VSTest when converting from xUnit to MSTest?

Yes. Retain the existing Microsoft.NET.Test.Sdk configuration and update it to a version compatible with the chosen MSTest release, or set UseVSTest to true when using MSTest.Sdk. The migration does not require switching to Microsoft.Testing.Platform.

When should I not use xUnit to MSTest conversion?

Do not use it for xUnit v2-to-v3 upgrades, MSTest version upgrades, NUnit or TUnit conversions, or runner-only VSTest-to-MTP migrations. If the project already uses MSTest with no xUnit constructs, no migration is needed.