Skip to content

Commit aa8bdb5

Browse files
authored
Migrate tests from xUnit to NUnit (#452)
* Migrate tests from xUnit to NUnit Replaces xUnit with NUnit in test projects, updates test attributes and assertions accordingly, and adjusts package references. This unifies the test framework across the codebase and ensures compatibility with NUnit tooling. * Update ci-build.yml
1 parent a549e68 commit aa8bdb5

File tree

7 files changed

+100
-119
lines changed

7 files changed

+100
-119
lines changed

.github/workflows/ci-build.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
name: Build
1+
name: Build
22

33
on:
44
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
8-
9-
env:
10-
productNamespacePrefix: "Fusillade"
5+
branches:
6+
- main # ✅ run on main
7+
pull_request: # (optional) run on PRs targeting any branch
8+
9+
# Needed so the reusable workflow can optionally delete the temp per-OS artifacts it creates.
10+
permissions:
11+
contents: read
12+
actions: write
1113

1214
jobs:
1315
build:
1416
uses: reactiveui/actions-common/.github/workflows/workflow-common-setup-and-build.yml@main
1517
with:
1618
configuration: Release
1719
productNamespacePrefix: "Fusilade"
18-
installWorkflows: false
20+
secrets:
21+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

src/Directory.build.props

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@
3232
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
3333
<PackageReference Include="ReactiveUI.Testing" Version="21.*" />
3434
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
35-
<PackageReference Include="xunit" Version="2.9.3" />
36-
<PackageReference Include="xunit.runner.console" Version="2.9.3" />
37-
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
38-
<PackageReference Include="Xunit.StaFact" Version="1.2.69" />
39-
<PackageReference Include="Verify.Xunit" Version="30.10.0" />
35+
<PackageReference Include="NUnit" Version="4.4.0" />
36+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
37+
<PackageReference Include="Verify.NUnit" Version="30.10.0" />
4038
<PackageReference Include="FluentAssertions" Version="8.8.0" />
4139
<PackageReference Include="PublicApiGenerator" Version="11.4.6" />
4240
<PackageReference Include="coverlet.msbuild" Version="6.0.4" PrivateAssets="All" />

src/Fusillade.Tests/API/ApiApprovalTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
using System.Diagnostics.CodeAnalysis;
77
using System.Threading.Tasks;
8-
using Xunit;
8+
using NUnit.Framework;
99

1010
namespace Fusillade.APITests
1111
{
@@ -19,7 +19,7 @@ public class ApiApprovalTests
1919
/// Tests to make sure the akavache project is approved.
2020
/// </summary>
2121
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
22-
[Fact]
23-
public Task FusilladeTests() => typeof(OfflineHttpMessageHandler).Assembly.CheckApproval(["Fusillade"]);
22+
[Test]
23+
public Task FusilladeTests() => typeof(OfflineHttpMessageHandler).Assembly.CheckApproval(new[] { "Fusillade" });
2424
}
2525
}

src/Fusillade.Tests/API/ApiExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
using System.Reflection;
99
using System.Runtime.CompilerServices;
1010
using System.Threading.Tasks;
11+
using NUnit.Framework; // add for NUnit attributes if needed later
1112
using PublicApiGenerator;
12-
using VerifyXunit;
13+
using VerifyNUnit; // changed from VerifyXunit
1314

1415
namespace Fusillade.APITests;
1516

src/Fusillade.Tests/Http/HttpSchedulerCachingTests.cs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414
using System.Threading.Tasks;
1515
using Akavache;
1616
using Akavache.SystemTextJson;
17-
using Xunit;
17+
using NUnit.Framework; // switched from xunit
1818

1919
namespace Fusillade.Tests.Http
2020
{
2121
/// <summary>
2222
/// Checks to make sure that the http scheduler caches correctly.
2323
/// </summary>
24+
[TestFixture]
2425
public class HttpSchedulerCachingTests
2526
{
2627
/// <summary>
2728
/// Checks to make sure that the caching functiosn are only called with content.
2829
/// </summary>
2930
/// <returns>A task to monitor the progress.</returns>
30-
[Fact]
31+
[Test]
3132
public async Task CachingFunctionShouldBeCalledWithContent()
3233
{
3334
var innerHandler = new TestHttpMessageHandler(_ =>
@@ -53,16 +54,16 @@ public async Task CachingFunctionShouldBeCalledWithContent()
5354
var client = new HttpClient(fixture);
5455
var str = await client.GetStringAsync(new Uri("http://lol/bar"));
5556

56-
Assert.Equal("foo", str);
57-
Assert.Equal(1, contentResponses.Count);
58-
Assert.Equal(3, contentResponses[0].Length);
57+
Assert.That(str, Is.EqualTo("foo"));
58+
Assert.That(contentResponses.Count, Is.EqualTo(1));
59+
Assert.That(contentResponses[0].Length, Is.EqualTo(3));
5960
}
6061

6162
/// <summary>
6263
/// Checks to make sure that the cache preserves the http headers.
6364
/// </summary>
6465
/// <returns>A task to monitor the progress.</returns>
65-
[Fact]
66+
[Test]
6667
public async Task CachingFunctionShouldPreserveHeaders()
6768
{
6869
var innerHandler = new TestHttpMessageHandler(_ =>
@@ -86,14 +87,14 @@ public async Task CachingFunctionShouldPreserveHeaders()
8687

8788
var client = new HttpClient(fixture);
8889
var resp = await client.GetAsync(new Uri("http://lol/bar"));
89-
Assert.Equal("\"worifjw\"", etagResponses[0]);
90+
Assert.That(etagResponses[0], Is.EqualTo("\"worifjw\""));
9091
}
9192

9293
/// <summary>
9394
/// Does a round trip integration test.
9495
/// </summary>
9596
/// <returns>A task to monitor the progress.</returns>
96-
[Fact]
97+
[Test]
9798
public async Task RoundTripIntegrationTest()
9899
{
99100
var aka = CacheDatabase.CreateBuilder().WithSerializerSystemTextJson().Build();
@@ -112,19 +113,18 @@ public async Task RoundTripIntegrationTest()
112113
var client = new HttpClient(cachingHandler);
113114
var origData = await client.GetStringAsync(new Uri("http://httpbin.org/get"));
114115

115-
Assert.True(origData.Contains("origin"));
116+
Assert.That(origData.Contains("origin"), Is.True);
116117

117-
// Some Akavache cache implementations expose a single key, not a collection.
118118
var singleKey = await cache.GetAllKeys();
119-
Assert.False(string.IsNullOrEmpty(singleKey));
120-
Assert.StartsWith("HttpSchedulerCache_", singleKey, StringComparison.Ordinal);
119+
Assert.That(string.IsNullOrEmpty(singleKey), Is.False);
120+
Assert.That(singleKey.StartsWith("HttpSchedulerCache_", StringComparison.Ordinal), Is.True);
121121

122122
var offlineHandler = new OfflineHttpMessageHandler(async (rq, key, ct) => await cache.Get(key));
123123

124124
client = new HttpClient(offlineHandler);
125125
var newData = await client.GetStringAsync(new Uri("http://httpbin.org/get"));
126126

127-
Assert.Equal(origData, newData);
127+
Assert.That(origData, Is.EqualTo(newData));
128128

129129
bool shouldDie = true;
130130
try
@@ -137,7 +137,7 @@ public async Task RoundTripIntegrationTest()
137137
Console.WriteLine(ex);
138138
}
139139

140-
Assert.False(shouldDie);
140+
Assert.That(shouldDie, Is.False);
141141
}
142142

143143
/// <summary>
@@ -146,14 +146,13 @@ public async Task RoundTripIntegrationTest()
146146
/// <param name="method">The name of the method.</param>
147147
/// <param name="shouldCache">If it should be cached or not.</param>
148148
/// <returns>A task to monitor the progress.</returns>
149-
[Theory]
150-
[InlineData("GET", true)]
151-
[InlineData("HEAD", true)]
152-
[InlineData("OPTIONS", true)]
153-
[InlineData("POST", false)]
154-
[InlineData("DELETE", false)]
155-
[InlineData("PUT", false)]
156-
[InlineData("WHATEVER", false)]
149+
[TestCase("GET", true)]
150+
[TestCase("HEAD", true)]
151+
[TestCase("OPTIONS", true)]
152+
[TestCase("POST", false)]
153+
[TestCase("DELETE", false)]
154+
[TestCase("PUT", false)]
155+
[TestCase("WHATEVER", false)]
157156
public async Task OnlyCacheRelevantMethods(string method, bool shouldCache)
158157
{
159158
var innerHandler = new TestHttpMessageHandler(_ =>
@@ -178,7 +177,7 @@ public async Task OnlyCacheRelevantMethods(string method, bool shouldCache)
178177
var request = new HttpRequestMessage(new(method), "http://lol/bar");
179178
await client.SendAsync(request);
180179

181-
Assert.Equal(shouldCache, cached);
180+
Assert.That(cached, Is.EqualTo(shouldCache));
182181
}
183182
}
184183
}

0 commit comments

Comments
 (0)