Context
The xunit.v3 packages are moving from 3.2.2 to 4.0.0 (still the "xUnit v3" generation, just a SemVer major bump due to breaking changes). The headline feature is Native AOT support. Pre-releases are available on the xunit CI feed (4.0.0-pre.117+).
CI feed: https://f.feedz.io/xunit/xunit/nuget/index.json
Breaking Changes That Affect DeviceRunners
1. FixtureMappingManager parameter added to runner Run() methods
XunitTestCaseRunner.Run() and XunitTestRunner.Run() now require a FixtureMappingManager parameter for fixture lifecycle management.
Affected files:
src/DeviceRunners.UITesting.Xunit3/UITestCase.cs — ISelfExecutingXunitTestCase.Run() calls UIXunitTestCaseRunner.Instance.Run()
src/DeviceRunners.UITesting.Xunit3/UITheoryTestCase.cs — same pattern
src/DeviceRunners.UITesting.Xunit3/UIXunitTestCaseRunner.cs — RunTest() calls UIXunitTestRunner.Instance.Run()
Fix: Create a new FixtureMappingManager("Method") and pass it as the last argument.
2. TheoryDiscoverer.CreateTestCasesForDataRow is no longer virtual
Cannot override it anymore.
Affected files:
src/DeviceRunners.UITesting.Xunit3/UITheoryDiscoverer.cs
Fix: Use new instead of override. Need to verify this still gets called correctly (may need to investigate how the base class invokes it in AOT mode).
3. XunitTestAssembly constructor marked obsolete
The old constructor XunitTestAssembly(Assembly, string?, Version?, string?) is obsolete. A new overload with additional parameters is available.
Affected files:
src/DeviceRunners.VisualRunners.Xunit3/InMemoryXunit3TestAssembly.cs
Fix: Suppress warning or migrate to new constructor. Note: The assemblyPath parameter was added to XunitTestAssembly (xunit/xunit#3577), which may allow removing InMemoryXunit3TestAssembly entirely if we can pass the logical path directly.
4. ExtensibilityPointFactory.GetTestFramework(Assembly) is obsolete
Replaced by RegisteredEngineConfig.GetTestFramework.
Affected files:
src/DeviceRunners.VisualRunners.Xunit3/InMemoryXunit3TestFramework.cs
Fix: Use RegisteredEngineConfig.GetTestFramework instead.
5. Xunit.Runners namespace removed
Replaced by Xunit.SimpleRunner. Likely does not affect us but worth checking.
Potential Simplification: Remove InMemory Workaround
With xunit/xunit#3577 fixed in 4.0.0, XunitTestAssembly now accepts an assemblyPath constructor parameter. This means InMemoryXunit3TestAssembly and InMemoryXunit3TestFramework may be entirely removable — we could pass the logical path directly to the standard XunitTestAssembly constructor.
Other Notable Changes in 4.0.0
- Native AOT support — test projects can be AOT-compiled
- Dropped Mono support — no longer officially supported
- Dropped Microsoft Testing Platform v1 — only v2 supported
- Test class & method orderers (new)
- Generic attribute support (.NET 8+):
TestFrameworkAttribute<T>, etc.
RemoveAsyncSuffix display option
- Numeric theory row indexing for sorting
ITestMetadata.TestLabel
- Native console runner as .NET Tool (
dotnet xunit-console)
StartTime/FinishTime on pipeline events
FixtureMappingManager.InitializeAsync() without createInstances removed
Action Items
References
Context
The xunit.v3 packages are moving from
3.2.2to4.0.0(still the "xUnit v3" generation, just a SemVer major bump due to breaking changes). The headline feature is Native AOT support. Pre-releases are available on the xunit CI feed (4.0.0-pre.117+).CI feed:
https://f.feedz.io/xunit/xunit/nuget/index.jsonBreaking Changes That Affect DeviceRunners
1.
FixtureMappingManagerparameter added to runnerRun()methodsXunitTestCaseRunner.Run()andXunitTestRunner.Run()now require aFixtureMappingManagerparameter for fixture lifecycle management.Affected files:
src/DeviceRunners.UITesting.Xunit3/UITestCase.cs—ISelfExecutingXunitTestCase.Run()callsUIXunitTestCaseRunner.Instance.Run()src/DeviceRunners.UITesting.Xunit3/UITheoryTestCase.cs— same patternsrc/DeviceRunners.UITesting.Xunit3/UIXunitTestCaseRunner.cs—RunTest()callsUIXunitTestRunner.Instance.Run()Fix: Create a
new FixtureMappingManager("Method")and pass it as the last argument.2.
TheoryDiscoverer.CreateTestCasesForDataRowis no longer virtualCannot
overrideit anymore.Affected files:
src/DeviceRunners.UITesting.Xunit3/UITheoryDiscoverer.csFix: Use
newinstead ofoverride. Need to verify this still gets called correctly (may need to investigate how the base class invokes it in AOT mode).3.
XunitTestAssemblyconstructor marked obsoleteThe old constructor
XunitTestAssembly(Assembly, string?, Version?, string?)is obsolete. A new overload with additional parameters is available.Affected files:
src/DeviceRunners.VisualRunners.Xunit3/InMemoryXunit3TestAssembly.csFix: Suppress warning or migrate to new constructor. Note: The
assemblyPathparameter was added toXunitTestAssembly(xunit/xunit#3577), which may allow removingInMemoryXunit3TestAssemblyentirely if we can pass the logical path directly.4.
ExtensibilityPointFactory.GetTestFramework(Assembly)is obsoleteReplaced by
RegisteredEngineConfig.GetTestFramework.Affected files:
src/DeviceRunners.VisualRunners.Xunit3/InMemoryXunit3TestFramework.csFix: Use
RegisteredEngineConfig.GetTestFrameworkinstead.5.
Xunit.Runnersnamespace removedReplaced by
Xunit.SimpleRunner. Likely does not affect us but worth checking.Potential Simplification: Remove InMemory Workaround
With xunit/xunit#3577 fixed in 4.0.0,
XunitTestAssemblynow accepts anassemblyPathconstructor parameter. This meansInMemoryXunit3TestAssemblyandInMemoryXunit3TestFrameworkmay be entirely removable — we could pass the logical path directly to the standardXunitTestAssemblyconstructor.Other Notable Changes in 4.0.0
TestFrameworkAttribute<T>, etc.RemoveAsyncSuffixdisplay optionITestMetadata.TestLabeldotnet xunit-console)StartTime/FinishTimeon pipeline eventsFixtureMappingManager.InitializeAsync()withoutcreateInstancesremovedAction Items
Directory.Packages.propsxunit.v3 versions to 4.0.0 (when stable)FixtureMappingManagerparameter to allRun()call sitesoverridetonewonUITheoryDiscoverer.CreateTestCasesForDataRowInMemoryXunit3TestFramework.CreateForAssemblytoRegisteredEngineConfig.GetTestFrameworkInMemoryXunit3TestAssembly/InMemoryXunit3TestFrameworkentirely (use newassemblyPathconstructor param)References