Logo Migrate Nunit To Mstest

Migrate Nunit To Mstest

Tổ chức
managedcode
migrate-nunit-to-mstest

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.

Tổng quan

Nhà phát hànhmanagedcode
Kho mãdotnet-skills
Tên kỹ năngmigrate-nunit-to-mstest
Sao
498
Bản fork
40
Tệp đi kèm
2
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 2 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được managedcode công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Migrate Nunit To Mstest trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/managedcode/dotnet-skills/tree/main/catalog/Testing/Official-DotNet-Test-Migration/skills/migrate-nunit-to-mstest
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/managedcode/dotnet-skills.git /tmp/dotnet-skills
mkdir -p .claude/skills
cp -r /tmp/dotnet-skills/catalog/Testing/Official-DotNet-Test-Migration/skills/migrate-nunit-to-mstest .claude/skills/migrate-nunit-to-mstest
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Migrate Nunit To Mstest trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Migrate Nunit To Mstest ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Migrate Nunit To Mstest không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

NUnit -> MSTest Migration

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.

Scope

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.

Workspace Contract

  • Search the current working directory for projects and source; never look for user files under this skill's directory.
  • Classify the deliverable: "convert this project" means edit, build, and test; "give me a plan" means answer without editing.
  • Preserve the user's requested project scope. Shared props may be changed only when they own NUnit package or runner configuration for that scope.
  • The final response must state the source NUnit version, preserved runner, changed files, high-risk semantic mappings, and actual test counts.

Response Mode

  • Full migration request: inspect, edit, build, and run tests. Do not stop after a plan.
  • Focused compile error or API question: apply only the relevant mapping.
  • Unsupported target framework: stop before changing packages. MSTest v4 requires .NET 8+ or .NET Framework 4.6.2+ for test applications; offer a separately approved TFM upgrade or MSTest v3.

Decisions That Change the Result

Detected stateRequired action
No NUnit package, namespace, attribute, or constraint remainsStop, make no changes, and run the existing test command once to prove the already-MSTest project is healthy.
Source uses VSTestPreserve VSTest. Retain and update an explicit Microsoft.NET.Test.Sdk pin when the repository owns one; do not introduce MTP properties.
Source uses MTPReplace 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 lifecycleNUnit 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 configurationPreserve serial execution. Do not add [assembly: Parallelize]; NUnit and MSTest are both serial by default.
NUnit explicitly enables parallel executionTranslate 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.

Fast Path

For a routine migration, converge in four phases: one batched discovery pass, one edit pass, one dotnet test, and one concise result.

  • Use an existing CI/test result as the baseline when available.
  • Run a pre-edit baseline when counts are unavailable and the project contains parameterized tests, fixture state, namespace setup, retries, custom attributes, or explicit parallelization.
  • Do not run separate restore, build, and test commands when dotnet test is sufficient.
  • Do not delete NUnit runner configuration until its behavior has been translated.

Workflow

1. Establish the baseline

  1. Batch-read test projects, central package files, global.json, .runsettings, testconfig.json, and NUnit configuration.
  2. Detect NUnit from NUnit, NUnit3TestAdapter, NUnit.Analyzers, NUnit.Framework, NUnit.Framework.Legacy, and using NUnit.Framework.
  3. State whether the source is NUnit 3 or 4 from the resolved package version.
  4. Detect VSTest or MTP and preserve it. Use platform-detection only when ambiguous.
  5. Record target frameworks and stop if MSTest v4 does not support them.
  6. Inventory high-risk constructs:
    • [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 setup
    • Assert.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 aliases

2. Replace packages without switching runners

Remove 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:

xml
<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.

3. Perform the mechanical conversion

NUnitMSTest
[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.

4. Resolve semantic mappings

Load the mapping cheatsheet for every high-risk construct found in Step 1. These rules are mandatory:

  • NUnit's default 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.
  • NUnit 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>.
  • NUnit Is.TypeOf<T> maps to Assert.IsExactInstanceOfType<T>; Is.InstanceOf<T> maps to Assert.IsInstanceOfType<T>.
  • NUnit equality constraints compare sequences element-by-element. Use 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.
  • Preserve per-row names, categories, and ignores by returning 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.
  • MSTest 4.4 combinatorial attributes can map NUnit [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.
  • NUnit [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.
  • Convert [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.
  • NUnit [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.
  • Map NUnit platform and culture gates to OSCondition, ArchitectureCondition, or a MemberCondition helper. Map SetCulture and SetUICulture to setup/cleanup that saves and restores the original culture.
  • Expand [DefaultFloatingPointTolerance] into explicit deltas on every affected assertion. Preserve method-over-fixture-over-assembly precedence.

5. Preserve lifecycle and namespace setup

  • [SetUp] and [TearDown] remain per-test lifecycle methods.
  • For NUnit's default single fixture instance, audit every mutable instance field. If tests depend on sharing, use static state created by [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.
  • Preserve setup/cleanup inheritance order. Do not merge base and derived methods unless the resulting order is proven equivalent.
  • Map NUnit TestContext.WriteLine to an injected or property-based MSTest TestContext.WriteLine. Translate directory, test-name, and attachment APIs individually.

6. Preserve parallelization and ordering

NUnit and MSTest both run serially by default. Do not add parallelization for an unconfigured NUnit project.

When NUnit explicitly opts in:

  • assembly [Parallelizable(ParallelScope.Fixtures)] -> [assembly: Parallelize(Workers = N, Scope = ExecutionScope.ClassLevel)]
  • fixture [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
  • resource-specific serialization can use MSTest 4.4 [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.

7. Verify parity

  1. Run tests with the same platform, filter, and configuration used for the baseline.
  2. Compare discovered, passed, failed, and skipped counts.
  3. Investigate every difference:
    • missing rows -> DataRow, DynamicData, combinatorial, or row metadata conversion
    • changed exceptions/types -> exact-vs-derived mapping
    • state failures -> NUnit single-instance fixture semantics or setup order
    • concurrency failures -> Parallelize, DoNotParallelize, worker count, or resource locks
    • changed skips -> Ignore, Explicit, row-level ignore, or retry behavior
  4. Confirm no NUnit package, namespace, attribute, constraint, adapter setting, or custom NUnit extension remains unless documented for follow-up.
  5. Read back high-risk changed files and name the exact target APIs in the result.

Use this final response shape:

  • Changed: files and exact high-risk mappings.
  • Verified: final command and discovered/passed/failed/skipped counts.
  • Preserved: target framework, test platform, fixture scope, and concurrency choice.
  • Remaining: manual follow-up, or none.

Completion Criteria

  • NUnit version and test platform were identified
  • NUnit packages and source constructs were converted
  • Target framework and test platform stayed unchanged
  • Default single-instance fixture semantics were audited and preserved where observable
  • Data-row metadata and assertion semantics were preserved
  • Namespace setup and parallelization scope were not silently widened
  • Every attribute on NUnit's official attribute index was classified as direct, rewritten, removed, or manual
  • Build succeeds and test results match the baseline
  • Unsupported custom extensions or behavior are called out

Follow-up

Run migrate-vstest-to-mtp separately if the user also wants MTP. Use writing-mstest-tests only after parity is established.

Tệp đi kèm

Mô hình đọc các tệp này khi cần trong lúc kỹ năng được tải. Các tệp được cung cấp ở dạng có thể đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Migrate Nunit To Mstest làm được gì?

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.

Vì sao nên dùng Migrate Nunit To Mstest trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Migrate Nunit To Mstest là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Migrate Nunit To Mstest trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/managedcode/dotnet-skills/tree/main/catalog/Testing/Official-DotNet-Test-Migration/skills/migrate-nunit-to-mstest. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Migrate Nunit To Mstest?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Migrate Nunit To Mstest với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Migrate Nunit To Mstest với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Migrate Nunit To Mstest có miễn phí không?

Có. Kỹ năng này được managedcode phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇