-
-
Notifications
You must be signed in to change notification settings - Fork 0
Migrate test projects from xUnit to NUnit 4.4.0 #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@copilot You're going to have to re-install all the .NET sdks, since it has a different path, so install 8/9/10 |
Re-installed .NET 8, 9, and 10 SDKs to the system location (/usr/share/dotnet). All SDKs are now available, repository is unshallowed, workloads restored, and tests pass successfully. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: glennawatson <[email protected]>
|
@copilot Get the latest commit, do the normal prereq (install .NET 8/9/10 regardless if any is installed yet since its required due to the environment path changes, unshallow the commits, and dotnet workload restore). I've enabled nunit analyzers and there's a bunch of the tests failing now due to the analyzers. Determine the build errors and fix. |
Co-authored-by: glennawatson <[email protected]>
Completed all prerequisites and fixed NUnit analyzer errors:
All tests passing, build succeeds with no warnings or errors. Commit: 2316e93 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Migration plan for xUnit to NUnit 4.4.0:
Summary
Successfully migrated all test projects from xUnit + FluentAssertions to NUnit 4.4.0 with NUnit.Analyzers enabled.
Latest Changes:
Fixed NUnit analyzer errors (NUnit4002) by replacing
Assert.That(result, Is.EqualTo(0))withAssert.That(result, Is.Zero)in 4 test methods. This follows NUnit best practices for comparing numeric values to zero.Verification:
Original prompt
This section details on the original issue you should resolve
<issue_title>Migrate xUnit to nUnit</issue_title>
<issue_description># Migrate xUnit + FluentAssertions to NUnit 4.4.0 with Controlled Concurrency
Prereq steps that must be done for you to be able to compile (see copilot-instructions.md in the .github folder for further details)
1, Install .net 8/9/10 via the install script.
2. unshallow the commits
3. dotnet workload restore in the /src folder
1. Update Test Project Packages
Remove
xunitxunit.runner.visualstudioFluentAssertionsAdd
NUnit(4.4.0)NUnit3TestAdapter(latest stable, e.g., 5.2.0)Microsoft.NET.Test.Sdk(latest stable, e.g., 18.0.1 )Updated
.csprojExample:2. Configure Concurrency for Static Classes
To prevent concurrency issues with ReactiveUI's static classes, run tests sequentially within each test fixture (class) but allow parallelism across fixtures.
2.1 Assembly-Level Concurrency
Add an
AssemblyInfo.Parallel.csfile (outside any namespace) in each test project:ParallelScope.Fixtures: Runs test fixtures in parallel, but tests within each fixture sequentially.LevelOfParallelism(4): Caps parallel workers (adjust based on CI resources, e.g., CPU count/2).2.2 CI Runsettings
Create a
tests.runsettingsfile at the repo root:Usage:
dotnet test --settings tests.runsettingsOverride for full serialization (if static state is fragile):
dotnet test -- NUnit.NumberOfTestWorkers=13. xUnit to NUnit Attribute & API Mappings
[Fact][Test][Theory]+[InlineData(...)][TestCase(...)][Theory]+[MemberData][TestCaseSource(nameof(Data))][Theory]+[ClassData<T>][TestCaseSource(typeof(T))]Assert.Equal(a,b)Assert.That(b, Is.EqualTo(a))Assert.NotEqual(a,b)Assert.That(b, Is.Not.EqualTo(a))Assert.True(expr)Assert.That(expr, Is.True)Assert.False(expr)Assert.That(expr, Is.False)Assert.Null(x)Assert.That(x, Is.Null)Assert.NotNull(x)Assert.That(x, Is.Not.Null)Assert.Throws<T>(...)Assert.Throws<T>(...)orAssert.That(..., Throws.TypeOf<T>())Assert.Collection/ContainsAssert.That(coll, Does.Contain(item))Trait("Category","X")[Category("X")]IClassFixture<T>[OneTimeSetUp]/[OneTimeTearDown]with shared state[Collection("name")][NonParallelizable]on conflicting fixturesNOTE: for multiple asserts use the IDisposable
Assert.EnterMultipleScopemethod.4. Remove FluentAssertions: Convert to Assert.That
Common Conversions:
actual.Should().Be(expected)Assert.That(actual, Is.EqualTo(expected))actual.Should().NotBe(expected)Assert.That(actual, Is.Not.EqualTo(expected))flag.Should().BeTrue()Assert.That(flag, Is.True)value.Should().BeNull()Assert.That(value, Is.Null)str.Should().Contain("x")Assert.That(str, Does.Contain("x"))str.Should().StartWith("pre")Assert.That(str, Does.StartWith("pre"))n.Should().BeGreaterThan(5)Assert.That(n, Is.GreaterThan(5))n.Should().BeInRange(1,10)Assert.That(n, Is.InRange(1,10))items.Should().BeEmpty()Assert.That(items, Is.Empty)items.Should().BeEquivalentTo(new[] {1,2,3})Assert.That(items, Is.EquivalentTo(new[] {1,2,3}))act.Should().Throw<InvalidOperationException>()Assert.That(act, Throws.TypeOf<InvalidOperationException>())💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.