Successfully migrated ReactiveUI.Validation test suite from xUnit + FluentAssertions to NUnit 4.4.0.
Removed:
xunit(2.9.3)xunit.runner.visualstudio(3.1.4)xunit.runner.console(2.9.3)Xunit.StaFact(1.2.69)FluentAssertions(8.6.0)Verify.Xunit(30.10.0)
Added:
NUnit(4.4.0)NUnit3TestAdapter(5.*)Verify.NUnit(30.*)
Updated:
DiffEngine(16.2.3 → 16.*)Microsoft.NET.Test.Sdk(already at 17.14.1)
Created AssemblyInfo.Parallel.cs:
[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(4)]- Tests run sequentially within each fixture
- Parallel execution across different fixtures
- 4 parallel workers
Created tests.runsettings:
<RunSettings>
<NUnit>
<NumberOfTestWorkers>4</NumberOfTestWorkers>
</NUnit>
</RunSettings>All test files migrated from xUnit to NUnit:
- ApiApprovalTests.cs - Changed from
[Fact]to[Test], updated to useVerify.NUnit - ApiExtensions.cs - Updated imports to use
VerifyNUnit - MemoryLeakTests.cs - Converted assertions, replaced
ITestOutputHelperwithTestContext.WriteLine - NotifyDataErrorInfoTests.cs - Converted all xUnit assertions to NUnit
Assert.That()style - ObservableValidationTests.cs - Added
[SetUp]method, converted field initialization - PropertyValidationTests.cs - Converted assertions, added
Assert.Multiple()for grouped assertions - ValidationBindingTests.cs - Converted all assertions to NUnit constraints
- ValidationContextTests.cs - Converted assertions with extensive use of
Assert.Multiple() - ValidationTextTests.cs - Converted assertions with
Assert.Multiple()
From xUnit/FluentAssertions to NUnit:
| Old Syntax | New Syntax |
|---|---|
Assert.True(x) |
Assert.That(x, Is.True) |
Assert.False(x) |
Assert.That(x, Is.False) |
Assert.Equal(a, b) |
Assert.That(b, Is.EqualTo(a)) |
Assert.Same(a, b) |
Assert.That(b, Is.SameAs(a)) |
Assert.Null(x) |
Assert.That(x, Is.Null) |
Assert.Empty(x) |
Assert.That(x, Is.Empty) |
Assert.Single(x) |
Assert.That(x, Has.Count.EqualTo(1)) |
x.Should().Be(y) |
Assert.That(x, Is.EqualTo(y)) |
x.Should().BeTrue() |
Assert.That(x, Is.True) |
x.Should().BeFalse() |
Assert.That(x, Is.False) |
Key Improvements:
- Used
Assert.Multiple()to group related assertions - Used proper NUnit constraints (e.g.,
Is.GreaterThan,Is.Empty,Has.Count) - Converted comparison operations to use
.Count()where needed forIEnumerable<T>
xunit.runner.json- No longer needed with NUnit
Passed! - Failed: 0, Passed: 68, Skipped: 0, Total: 68
Tested on:
- ✅ net8.0 (Duration: 368 ms)
- ✅ net9.0 (Duration: 589 ms)
-
Parallelization Strategy: Tests within each fixture run sequentially (to handle ReactiveUI's static state), but different fixtures can run in parallel.
-
Assert.Multiple(): Extensively used for grouping related assertions, improving test readability and failure reporting.
-
Constraint Model: Full adoption of NUnit's constraint model (
Assert.That()) provides more readable and maintainable test code. -
No Breaking Changes: All existing test logic preserved; only the testing framework and assertion syntax changed.
-
Performance: Similar test execution times compared to xUnit baseline.
Standard run:
dotnet test --settings tests.runsettingsForce full serialization (if needed):
dotnet test -- NUnit.NumberOfTestWorkers=1Target specific framework:
dotnet test -f net8.0 --settings tests.runsettings