跳到正文
Skillpedia
测试5.8k · #14622

migrate-xunit-to-xunit-v3

它能做什么

这项技能把 .NET 测试项目从 xUnit.net v2 升级到 xunit.v3,即 xUnit 测试库的较新版本。适合测试在迁移到 v3 后无法编译或行为不同的团队。

适用场景

  • ✓当测试项目引用 xunit v2 包,并应迁移到 xunit.v3 时。
  • ✓当把 xunit 包更新到版本 3 后出现编译错误时。
  • ✓当升级后自定义测试特性或异步测试出现故障的时候。

技能链接

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

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/dotnet/skills/blob/main/plugins/dotnet-test-migration/skills/migrate-xunit-to-xunit-v3/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请把我的 xUnit v2 测试项目升级到 xunit.v3,并修复所有导致无法构建的问题。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会更新包引用和项目设置,修复 v3 所要求的源代码改动,并运行测试以检查结果是否一致。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

xunit.v3 Migration

Migrate .NET test projects from xUnit.net v2 to xUnit.net v3. The outcome is a solution where all test projects reference xunit.v3.* packages, compiles cleanly, and all tests pass with the same results as before migration.

When to Use

  • Upgrading test projects from xunit (v2) packages to xunit.v3
  • Resolving compilation errors after updating xunit package references to v3

When Not to Use

  • Migrating between test frameworks (e.g., MSTest or NUnit to xUnit.net) — different effort entirely
  • Migrating from VSTest to Microsoft.Testing.Platform — use migrate-vstest-to-mtp
  • The projects already reference xunit.v3 — migration is done

Inputs

Input Required Description
Test project or solution No Discover .csproj, .sln, .slnx, central props, and source in the current working directory; ask only if none are found or the target is ambiguous

Workspace and Completion Contract

  • Skill activation is not completion. For migrate/fix/update requests, inspect the staged files, edit them, and run tests in the same task.
  • The skill base directory contains only guidance. Search the current working directory and open paths exactly as returned.
  • If a tool rejects a searched path, classify the rejection before retrying. Only a positively confirmed reader/path-normalization limitation with authorized access permits retrying through another permitted reader/editor.
  • On a permission, policy, or content-exclusion denial, stop that path and report the blocker. Never bypass the denial through other tools, shell commands, aliases, or agents, or infer or reconstruct the restricted content.
  • If the rejection reason is unclear, treat the path as unavailable, not missing. Continue only independently permitted work and explicitly disclose the incomplete migration.
  • Do not ask the user to provide a path while workspace discovery can find it.
  • Inventory project/central package files and all affected source in one pass. A package-only migration is incomplete when v2-only APIs remain.
  • End with the detected source version and runner, exact package compatibility set, files changed, discovered/passed/failed/skipped counts, and any platform-specific result. A build without test discovery is not success.
  • Package validity is empirical: record the configured feed query or resolved package graph and a successful restore. In the final result, say how the selected exact versions were proven available; do not merely name a version and leave a judge or user to infer whether it exists.

Workflow

Commit strategy: Do not create commits unless the user asks. Keep project configuration and source edits logically separable in the diff, but finish and verify the whole requested migration.

Prioritization: Steps 1-5 are required for every migration. Steps 6-12 are conditional — only apply the ones relevant to the project's code patterns. Skip steps that don't apply.

Decisions that change the result

Run this preflight before editing:

Detected state Required action
Project references xunit.v3, has the required executable/runner configuration, contains no remaining v2 packages or v2-only API patterns, and its existing test command passes Stop: migration is already complete. Do not update versions, create props files, or modify source. Report the verified no-op result. If any required v3 adaptation remains, make only that repair instead of treating the package reference alone as completion.
xUnit v2 uses YTest.MTP.XUnit2 Preserve MTP: remove that shim, set UseMicrosoftTestingPlatformRunner=true, and do not add xunit.runner.visualstudio or IsTestingPlatformApplication=false.
xUnit v2 does not use the MTP shim Preserve VSTest: keep/update xunit.runner.visualstudio and set IsTestingPlatformApplication=false.
A custom type derives from BeforeAfterTestAttribute Preserve that inheritance and its behavior. Add the IXunitTest parameter to both overrides and pass it to base.Before/base.After; do not replace the subclass with a direct interface implementation.
A Type-based collection/orderer attribute points to a custom type Migrate both the attribute syntax and the referenced type's v3 contract. For a collection factory, implement the required xUnit v3 IXunitTestCollectionFactory behavior; compiling the attribute while leaving an empty factory is not
常见问题

我的测试结果会保持不变吗?

目标是与升级前的结果相同,这项技能会运行测试来进行检查。

它会切换测试平台吗?

不会。它保留现有的运行器,迁移到 Microsoft.Testing.Platform 是单独的技能。

它涵盖从 MSTest 或 NUnit 迁移吗?

不涵盖。在框架之间迁移是一项不同且更大的工作。

详情

作者的原始描述

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

repo: dotnet/skills

热度

GitHub 星标
5.8k
排名
#14622
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能