Chuyển đến nội dung
Skillpedia
Kiểm thử5.8k · #14619

migrate-nunit-to-mstest

Skill này làm gì

Skill này chuyển test NUnit trong project .NET sang MSTest v4 mà vẫn giữ hành vi test. Skill dành cho các đội muốn chuyển framework test sang MSTest mà không thay đổi những gì test kiểm tra.

Khi nào nên dùng

  • ✓Khi một project test .NET dùng NUnit và bạn muốn chuyển sang MSTest.
  • ✓Khi bạn muốn thay các attribute, khẳng định và method thiết lập của NUnit bằng bản tương đương của MSTest.
  • ✓Khi bạn muốn có kế hoạch chuyển test NUnit mà chưa sửa file nào.

Liên kết skill

https://github.com/dotnet/skills/blob/main/plugins/dotnet-test-migration/skills/migrate-nunit-to-mstest/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/dotnet/skills/blob/main/plugins/dotnet-test-migration/skills/migrate-nunit-to-mstest/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Chuyển project test NUnit của tôi sang MSTest v4, và đảm bảo các test vẫn chạy và đạt như trước.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm các package và attribute NUnit, chuyển chúng sang bản tương đương MSTest, rồi build project và chạy test để xác nhận kết quả giống nhau.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

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], `[Dat
Câu hỏi thường gặp

Skill có nâng cấp phiên bản .NET luôn không?

Không. Đổi target framework là một bước riêng và không nằm trong việc chuyển đổi này.

Các test giống nhau có vẫn được tìm thấy không?

Đó là mục tiêu. Skill kiểm tra rằng cùng các test case được phát hiện sau khi chuyển đổi.

Nếu tôi chỉ muốn có kế hoạch thì sao?

Skill có thể trả lời bằng một kế hoạch và không thực hiện thay đổi nào.

Chi tiết

Mô tả gốc của tác giả

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.

repo: dotnet/skills

Độ phổ biến

Sao GitHub
5.8k
Vị trí xếp hạng
#14619
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự