用途:把 .NET 测试项目从 xUnit.net v2 迁移到 xUnit.net v3,目标是所有测试项目引用 xunit.v3.* 包、编译通过、测试结果与迁移前一致。仅用于升级 xunit 到 xunit.v3;不用于测试框架间迁移(如 MSTest、NUnit 转 xUnit),此类场景改用 migrate-vstest-to-mtp。输入为包含 xUnit.net v2 测试项目的 .NET 项目或解决方案。
主要步骤:先识别引用 xunit、xunit.abstractions、xunit.assert、xunit.core、xunit.extensibility.core/execution、xunit.runner.visualstudio 的项目,检查 Directory.Build.props/targets 与 Directory.Packages.props;确认目标框架为 .NET 8+ 或 .NET Framework 4.7.2+(测试库项目支持 .NET Standard 2.0),否则先升级框架,并要求 SDK 风格项目。然后按映射更新包引用:xunit→xunit.v3,xunit.abstractions 删除,xunit.assert→xunit.v3.assert,xunit.core→xunit.v3.core,两个 extensibility 合并为 xunit.v3.extensibility.core,并更新 xunit.runner.visualstudio。非测试库项目设置 OutputType 为 Exe。测试平台按原状保留:若引用 YTest.MTP.XUnit2 则移除并加 UseMicrosoftTestingPlatformRunner,否则加 IsTestingPlatformApplication=false 保持在 VSTest。移除 using Xunit.Abstractions。
条件步骤:async void 测试方法改 async Task;CollectionBehavior、TestCaseOrderer、TestCollectionOrderer、TestFramework 等特性参数由两个字符串改为 System.Type;继承 FactAttribute/TheoryAttribute 的自定义特性需加入 CallerFilePath/CallerLineNumber 并传给基类;继承 BeforeAfterTestAttribute 的 Before/After 覆写需增加 IXunitTest 参数;处理 xUnit1051 等新分析器警告;移除 Xunit.SkippableFact 并把 SkippableFact 改为 Fact、Skip.If 改为 Assert.SkipWhen、Skip.IfNot 改为 Assert.SkipUnless;Xunit.Combinatorial 1.x→2.x、Xunit.StaFact 1.x→3.x。最后构建并用 dotnet test 验证。
限制:仅针对上述已列明场景,其他平台迁移、收费与价格信息暂未提供。