/dotnet-test-migration:migrate-nunit-to-mstestfrom dotnet-test-migration
Convert .NET tests from NUnit 3/4 to MSTest v4 while preserving VSTest or MTP. Use for replacing NUnit/NUnit3TestAdapter packages, Test/TestCase/ TestCaseSource/Values attributes, constraint assertions, SetUp/TearDown, OneTimeSetUp, SetUpFixture, FixtureLifeCycle, TestContext, categories, retries, timeouts, and NUnit parallelization. Also use when a "convert NUnit to MSTest" request may already be migrated: inspect and report the no-op. Do not use for NUnit version upgrades, xUnit/TUnit conversion, MSTest upgrades, or runner-only VSTest-to-MTP migration.
Ships in dotnet-test-migration. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Convert NUnit 3 or 4 tests to MSTest v4 without changing the target framework or test platform. A successful migration builds, discovers the same test cases, and preserves pass/fail, lifecycle, data, filtering, and concurrency semantics.
Use this skill only when the project contains NUnit packages or source and the user wants MSTest. If the project already uses MSTest and contains no NUnit tests, report that no framework migration is needed and make no changes.
Do not combine this framework conversion with a target-framework upgrade or VSTest/MTP migration. Complete and verify one migration before starting another.
| Detected state | Required action |
|---|---|
| No NUnit package, namespace, attribute, or constraint remains | Stop, make no changes, and run the existing test command once to prove the already-MSTest project is healthy. |
| Source uses VSTest | Preserve VSTest. Retain and update an explicit Microsoft.NET.Test.Sdk pin when the repository owns one; do not introduce MTP properties. |
| Source uses MTP | Replace NUnit-specific MTP configuration with MSTest MTP configuration. Prefer MSTest.Sdk; with the metapackage set EnableMSTestRunner=true and OutputType=Exe. |
| NUnit uses its default fixture lifecycle | NUnit normally shares one fixture instance across all test cases; MSTest creates a new class instance per test. Move state that must remain class-shared behind static fields initialized by [ClassInitialize], or prove the state is per-test before leaving it as an instance field. |
NUnit has no Parallelizable configuration | Preserve serial execution. Do not add [assembly: Parallelize]; NUnit and MSTest are both serial by default. |
| NUnit explicitly enables parallel execution | Translate the effective scope and worker count. Never infer method-level parallelism from fixture-level settings. |
For detailed mappings, search references/mapping-cheatsheet.md for constructs present in the project and read only those sections.
For a routine migration, converge in four phases: one batched discovery pass, one edit pass, one dotnet test, and one concise result.
dotnet test is sufficient.global.json, .runsettings, testconfig.json, and NUnit configuration.NUnit, NUnit3TestAdapter, NUnit.Analyzers, NUnit.Framework, NUnit.Framework.Legacy, and using NUnit.Framework.platform-detection only when ambiguous.[TestFixture(...)], [TestFixtureSource], [FixtureLifeCycle], constructors with parameters[TestCase], [TestCaseSource], TestCaseData, [Values], [Range], [Random], [Sequential], [Pairwise], custom data attributes[Theory], [Datapoint], [DatapointSource], automatic bool/enum datapoints, Assume.That[OneTimeSetUp], [OneTimeTearDown], [SetUpFixture], inheritance-based setupAssert.That, Assert.Multiple, Assert.Throws, Assert.Catch, collection constraints[Parallelizable], [NonParallelizable], [LevelOfParallelism], [Order], [SingleThreaded][Apartment], [RequiresThread], [CancelAfter], [Timeout][Culture], [Platform], [SetCulture], [SetUICulture][Explicit], [Repeat], [Retry], [MaxTime], categories, properties, [TestOf][DefaultFloatingPointTolerance], [NonTestAssembly], and deprecated fixture lifecycle aliasesRemove NUnit-specific packages being replaced, including NUnit, NUnit3TestAdapter, NUnit.Analyzers, NUnit console runner packages, and NUnit-specific MTP adapters.
Default to the current stable MSTest v4 metapackage resolved from the configured package source:
<PackageReference Include="MSTest" Version="4.4.0" />
The pin is illustrative for the current release; during a real migration resolve and pin the current stable version. Preserve an explicit Microsoft.NET.Test.Sdk dependency for VSTest when the source project owns one. When preserving MTP, prefer MSTest.Sdk; otherwise use EnableMSTestRunner=true and OutputType=Exe.
Do not change TargetFramework. Remove NUnit .runsettings adapter settings only after translating relevant behavior.
| NUnit | MSTest |
|---|---|
[TestFixture] or fixture with tests | [TestClass] |
[Test] | [TestMethod] |
[TestCase(...)] | [TestMethod] + [DataRow(...)] |
[TestCaseSource(nameof(Cases))] | [TestMethod] + [DynamicData(nameof(Cases))] |
[SetUp] / [TearDown] | [TestInitialize] / [TestCleanup] |
[OneTimeSetUp] / [OneTimeTearDown] | static [ClassInitialize] / [ClassCleanup] |
[Category(value)] | [TestCategory(value)] |
[Property(key, value)] | [TestProperty(key, value)] |
[Ignore("reason")] | [Ignore("reason")] plus [TestMethod] |
[Timeout(ms)] | [Timeout(ms)] plus [TestMethod] |
[Retry(n)] | [Retry(n - 1)] plus [TestMethod] when n > 1; remove it when n = 1 |
Remove using NUnit.Framework; and using NUnit.Framework.Legacy;. Add using Microsoft.VisualStudio.TestTools.UnitTesting; when using the metapackage; MSTest.Sdk supplies an implicit global using.
Do not mechanically seal classes or flatten inherited setup methods.
Load the mapping cheatsheet for every high-risk construct found in Step 1. These rules are mandatory:
LifeCycle.SingleInstance differs from MSTest's per-test class instances. Preserve class-shared fields explicitly.[OneTimeSetUp] and [OneTimeTearDown] become static MSTest methods. Move any instance state they use to a static holder rather than merely adding static.Assert.Throws<T> and Throws.TypeOf<T> require an exact exception type and map to Assert.ThrowsExactly<T>. NUnit Assert.Catch<T> and Throws.InstanceOf<T> permit derived types and map to Assert.Throws<T>.Is.TypeOf<T> maps to Assert.IsExactInstanceOfType<T>; Is.InstanceOf<T> maps to Assert.IsInstanceOfType<T>.Assert.AreSequenceEqual on MSTest 4.3+ or CollectionAssert.AreEqual with materialized lists; never use reference-based Assert.AreEqual for sequences.TestCase(ExpectedResult=...) and TestCaseData.Returns(...) require rewriting the target test to assert the expected result.TestDataRow<T> from DynamicData when needed. NUnit row properties have no direct TestDataRow<T> equivalent and require a custom data source or an explicit metadata decision.[Combinatorial], [Values], [Range], and [Random]; add using Microsoft.VisualStudio.TestTools.UnitTesting.Combinatorial;. Constructor semantics differ, so translate NUnit ranges and random bounds explicitly. [Sequential] still requires explicit rows or a custom data source.[Pairwise] has no MSTest built-in. Preserve the exact generated rows in DynamicData or use a verified pairwise ITestDataSource; full Cartesian combinations change test counts and execution cost.[Theory], [Datapoint], and [DatapointSource] into explicit DynamicData or combinatorial sources. Preserve automatic bool/enum values and the rule that a theory fails when every row violates its assumptions.[Explicit], [Repeat], parameterized fixtures, fixture sources, and Assert.Multiple have no behavior-identical mechanical mapping. Rewrite deliberately or report manual follow-up; never approximate silently.[Retry(n)] counts the initial attempt, while MSTest [Retry(n)] counts retries after the initial attempt. Subtract one and review NUnit RetryExceptions filters separately.[CancelAfter(ms)] maps to [Timeout(ms, CooperativeCancellation = true)]. Under VSTest, remove NUnit's injected CancellationToken parameter and use an injected or property-based TestContext.CancellationToken; VSTest otherwise treats it as missing data. Retain a method token only when the preserved runner is proven to support injection. Expand fixture-level defaults to every affected test and lifecycle method.[Apartment(ApartmentState.STA)] maps to [STATestClass] or [STATestMethod]. Set UseSTASynchronizationContext = true when async continuations must remain on the STA thread. MTA is the MSTest default. [RequiresThread] and [SingleThreaded] guarantee thread identity that MSTest attributes do not generally preserve; use a custom executor or report manual follow-up.OSCondition, ArchitectureCondition, or a MemberCondition helper. Map SetCulture and SetUICulture to setup/cleanup that saves and restores the original culture.[DefaultFloatingPointTolerance] into explicit deltas on every affected assertion. Preserve method-over-fixture-over-assembly precedence.[SetUp] and [TearDown] remain per-test lifecycle methods.[ClassInitialize] and released by [ClassCleanup].[FixtureLifeCycle(LifeCycle.InstancePerTestCase)] already matches MSTest class instantiation; remove the attribute and keep per-test instance state.[SetUpFixture] is namespace-scoped in NUnit. MSTest assembly initialization is assembly-wide. Use [AssemblyInitialize] only when the NUnit setup already covers the whole assembly; otherwise move setup into the affected classes or a shared helper without widening scope.TestContext.WriteLine to an injected or property-based MSTest TestContext.WriteLine. Translate directory, test-name, and attachment APIs individually.NUnit and MSTest both run serially by default. Do not add parallelization for an unconfigured NUnit project.
When NUnit explicitly opts in:
[Parallelizable(ParallelScope.Fixtures)] -> [assembly: Parallelize(Workers = N, Scope = ExecutionScope.ClassLevel)][Parallelizable(ParallelScope.Children)] or method-level parallelism -> method-level MSTest parallelization only after confirming shared instance state is safe[NonParallelizable] -> [DoNotParallelize] when parallelization is enabled[LevelOfParallelism(N)] -> Workers = N[ResourceLock("key")] when it preserves a narrower lock than [DoNotParallelize]NUnit [Order] is not general dependency semantics. Use MSTest 4.4 [DependsOn] only when the source truly expresses a prerequisite; otherwise remove ordering by making tests independent or report manual follow-up.
DataRow, DynamicData, combinatorial, or row metadata conversionParallelize, DoNotParallelize, worker count, or resource locksIgnore, Explicit, row-level ignore, or retry behaviorUse this final response shape:
Run migrate-vstest-to-mtp separately if the user also wants MTP. Use writing-mstest-tests only after parity is established.
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub fcakiroglu16/marketplace --plugin dotnet-test-migration7 skills in this plugin
/migrate-mstest-v1v2-to-v3Use this skill before answering or editing whenever an MSTest v1/v2 project is being upgraded or repaired for v3. Triggers include QualityTools assembly references; MSTest.TestFramework/TestAdapter 1.x-2.x; "upgrade to MSTest v3"; comparing v1 and v2 migration paths; choosing MSTest or MSTest.Sdk; CS0411/CS1503 after a v3 package bump; DataRow type mismatch, MSTEST0014, or "Test data doesn't match method parameters"; .testsettings/LegacySettings to .runsettings; timeout changes; and net5.0 or other dropped v3 TFMs. Still use it when packages say 3.x but migration source errors or legacy settings remain. Preserve VSTest/MTP. Do not use for a clean v3 project, v3-to-v4, framework conversion, or runner-only migration./migrate-mstest-v3-to-v4Use this skill before answering, planning, or editing any MSTest 3.x-to-4.x upgrade or post-upgrade failure. Triggers include "MSTest v4 breaking changes"; CS0507/CS0103/CS1061/CS1615; ExecuteAsync, CallerInfo, DisplayName, or custom TestMethodAttribute; ClassCleanupBehavior; ContainsKey; ThrowsExactly or ExpectedException; IsInstanceOfType out parameters; TestTimeout.Infinite; ManagedType; net6/net7 compatibility; TestCase.Id history; TestName in ClassInitialize; TreatDiscoveryWarningsAsErrors; discovery errors after a clean build; and MSTest.Sdk/MTP or vstest.console discovery changes. Do not use for v1/v2-to-v3 leftovers, framework conversion, runner-only migration, or a general .NET upgrade./migrate-vstest-to-mtpUse this skill before answering, planning, or editing whenever .NET tests or CI are switching from VSTest to Microsoft.Testing.Platform (MTP), or an MTP migration behaves differently. Triggers include "switch from VSTest"; MSTest/NUnit/xUnit MTP enablement; OutputType=Exe only for test projects in Directory.Build.props; EnableMSTestRunner, EnableNUnitRunner, UseMicrosoftTestingPlatformRunner, or YTest.MTP.XUnit2; .NET 10 global.json test.runner and TestingPlatformDotnetTestSupport; translating VSTest filters, logger, coverage, blame, or dump arguments; replacing VSTest@3; and exit code 8 or zero tests. Also use for xUnit v3 MTP filters during a v2-to-v3 upgrade. Do not use for framework conversion, TFM, UWP, or WinUI./migrate-xunit-to-mstestConvert .NET tests from xUnit.net v2/v3 to MSTest v4 while preserving VSTest or MTP. Use for replacing xunit packages, Fact/Theory/InlineData/MemberData, assertions, IClassFixture/ICollectionFixture, ITestOutputHelper, TestContext cancellation, traits/Owner, skips, timeouts, and xUnit parallelization. Also use when a "convert xUnit to MSTest" request may already be migrated: inspect and report the no-op. Do not use for xUnit v2-to-v3, MSTest upgrades, NUnit/TUnit conversion, or runner-only VSTest-to-MTP migration./migrate-xunit-to-xunit-v3Migrate .NET test projects from xUnit.net v2 to xunit.v3 and fix v3 breaks. Use for package/CPM conversion, OutputType=Exe, preserving the VSTest or MTP runner (including projects currently using YTest.MTP.XUnit2), incompatible TFMs, async void tests, string-to-Type attributes, custom Fact/Theory/BeforeAfterTest attributes, Xunit.SkippableFact, xunit.abstractions/extensibility consolidation, and Xunit.Combinatorial/StaFact compatibility. Do not use for framework conversion or a runner-only migration. For xUnit v3 MTP filter syntax, also use migrate-vstest-to-mtp./run-testsALWAYS USE before running .NET tests or answering with a test command or flags. Trigger on "run the tests", "exact dotnet test command", one test/class/category/trait/target framework, combined filters, `--filter-query`, `--no-build`, `--diag`, diagnostic logs, TRX, coverage collection, crash/hang dumps, filter errors, or unrecognized options. Chooses repository-compatible classic, VSTest, bridged MTP, or native MTP syntax for MSTest/xUnit/NUnit/TUnit. DO NOT USE for platform identification alone (platform-detection), writing or debugging test code, interpreting an existing coverage report, CI investigation, migration, or a persistent hot reload/watch loop.