Skip to content

Latest commit

 

History

History
123 lines (94 loc) · 3.94 KB

File metadata and controls

123 lines (94 loc) · 3.94 KB

Migration to NUnit 4.4.0 - Summary

Overview

Successfully migrated ReactiveUI.Validation test suite from xUnit + FluentAssertions to NUnit 4.4.0.

Changes Made

1. Package Updates (ReactiveUI.Validation.Tests.csproj)

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)

2. Parallelization Configuration

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>

3. Test File Migrations

All test files migrated from xUnit to NUnit:

  1. ApiApprovalTests.cs - Changed from [Fact] to [Test], updated to use Verify.NUnit
  2. ApiExtensions.cs - Updated imports to use VerifyNUnit
  3. MemoryLeakTests.cs - Converted assertions, replaced ITestOutputHelper with TestContext.WriteLine
  4. NotifyDataErrorInfoTests.cs - Converted all xUnit assertions to NUnit Assert.That() style
  5. ObservableValidationTests.cs - Added [SetUp] method, converted field initialization
  6. PropertyValidationTests.cs - Converted assertions, added Assert.Multiple() for grouped assertions
  7. ValidationBindingTests.cs - Converted all assertions to NUnit constraints
  8. ValidationContextTests.cs - Converted assertions with extensive use of Assert.Multiple()
  9. ValidationTextTests.cs - Converted assertions with Assert.Multiple()

4. Assertion Conversions

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 for IEnumerable<T>

5. Files Removed

  • xunit.runner.json - No longer needed with NUnit

Test Results

All Tests Passing ✅

Passed!  - Failed: 0, Passed: 68, Skipped: 0, Total: 68

Tested on:

  • ✅ net8.0 (Duration: 368 ms)
  • ✅ net9.0 (Duration: 589 ms)

Key Takeaways

  1. Parallelization Strategy: Tests within each fixture run sequentially (to handle ReactiveUI's static state), but different fixtures can run in parallel.

  2. Assert.Multiple(): Extensively used for grouping related assertions, improving test readability and failure reporting.

  3. Constraint Model: Full adoption of NUnit's constraint model (Assert.That()) provides more readable and maintainable test code.

  4. No Breaking Changes: All existing test logic preserved; only the testing framework and assertion syntax changed.

  5. Performance: Similar test execution times compared to xUnit baseline.

Running Tests

Standard run:

dotnet test --settings tests.runsettings

Force full serialization (if needed):

dotnet test -- NUnit.NumberOfTestWorkers=1

Target specific framework:

dotnet test -f net8.0 --settings tests.runsettings