From 1070562db24e846479cf6a159349c0275850291e Mon Sep 17 00:00:00 2001 From: Renovate Date: Sun, 27 Sep 2026 22:38:52 +0000 Subject: [PATCH 1/2] chore(deps): update dependency nunit to v5 --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 5ac3b6fb25..6ba4e051d7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -83,7 +83,7 @@ - + From e97238e57fa00c40b1cef40553ba9485e2169908 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Mon, 28 Sep 2026 17:42:09 +0100 Subject: [PATCH 2/2] Fix build and docs for NUnit 5 NUnit 5 still ships ClassicAssert in NUnit.Framework.Legacy (nunit.framework.legacy.dll), but moved StringAssert, CollectionAssert, FileAssert and DirectoryAssert back to the NUnit.Framework namespace, and Assert.ThrowsAsync now returns an awaitable Task. - Doc snippet generator: alias StringAssert/CollectionAssert to NUnit.Framework. - NUnit migration guide: await ThrowsAsync in the NUnit example (CS4014 under NUnit 5). - NUnit migration analyzer: also detect NUnit.Framework.StringAssert when probing whether NUnit is referenced. - Analyzer tests: reference NUnit's net8.0 build. NUnit 5's net10.0 build references System.Runtime 10.0 and raises CS1705 against the verifier's Net90 reference assemblies. --- docs/docs/migration/nunit.md | 2 +- .../Migrators/NUnitMigrationAnalyzer.cs | 4 +++- .../NUnitMigrationAnalyzerTests.cs | 22 ++++++++++++++++--- .../TUnit.Analyzers.Tests.csproj | 12 +++++++++- tools/TUnit.DocSnippetGenerator/Program.cs | 4 ++-- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/docs/docs/migration/nunit.md b/docs/docs/migration/nunit.md index e904b30a44..05dbf51fb3 100644 --- a/docs/docs/migration/nunit.md +++ b/docs/docs/migration/nunit.md @@ -290,7 +290,7 @@ await Assert.That(text).EndsWith(suffix); ```csharp // NUnit Assert.Throws(() => DoSomething()); -Assert.ThrowsAsync(async () => await DoSomethingAsync()); +await Assert.ThrowsAsync(async () => await DoSomethingAsync()); // NUnit 3/4: not awaited // TUnit Assert.Throws(() => DoSomething()); diff --git a/src/TUnit.Analyzers/Migrators/NUnitMigrationAnalyzer.cs b/src/TUnit.Analyzers/Migrators/NUnitMigrationAnalyzer.cs index 861c0c584d..5705eba627 100644 --- a/src/TUnit.Analyzers/Migrators/NUnitMigrationAnalyzer.cs +++ b/src/TUnit.Analyzers/Migrators/NUnitMigrationAnalyzer.cs @@ -48,6 +48,8 @@ protected override bool IsFrameworkAvailable(Compilation compilation) // This prevents false positives after migration when NUnit assembly has been removed return compilation.GetTypeByMetadataName("NUnit.Framework.TestAttribute") != null || compilation.GetTypeByMetadataName("NUnit.Framework.Legacy.ClassicAssert") != null || - compilation.GetTypeByMetadataName("NUnit.Framework.Legacy.StringAssert") != null; + compilation.GetTypeByMetadataName("NUnit.Framework.Legacy.StringAssert") != null || + // NUnit 5 moved StringAssert/CollectionAssert/FileAssert/DirectoryAssert back to NUnit.Framework + compilation.GetTypeByMetadataName("NUnit.Framework.StringAssert") != null; } } \ No newline at end of file diff --git a/tests/TUnit.Analyzers.Tests/NUnitMigrationAnalyzerTests.cs b/tests/TUnit.Analyzers.Tests/NUnitMigrationAnalyzerTests.cs index 21c4c22058..7762fe1f93 100644 --- a/tests/TUnit.Analyzers.Tests/NUnitMigrationAnalyzerTests.cs +++ b/tests/TUnit.Analyzers.Tests/NUnitMigrationAnalyzerTests.cs @@ -5734,16 +5734,32 @@ await CodeFixer.VerifyCodeFixAsync( ); } + // NUnit 5 ships a net10.0 build referencing System.Runtime 10.0, which raises CS1705 against the + // verifiers' Net90 reference assemblies when the test runs on net10.0. The csproj copies NUnit's + // net8.0 build into the output directory; reference that instead of the runtime-loaded assembly. + private static string GetNUnitDllPath(string assemblyName) + { + var path = Path.Combine(AppContext.BaseDirectory, $"{assemblyName}.net8.0.dll"); + if (!File.Exists(path)) + { + throw new FileNotFoundException( + $"net8.0 build of {assemblyName} not found at '{path}'. Run 'dotnet build' before running analyzer tests.", + path); + } + + return path; + } + private static void ConfigureNUnitTest(Verifier.Test test) { - test.TestState.AdditionalReferences.Add(typeof(NUnit.Framework.TestAttribute).Assembly); + test.TestState.AdditionalReferences.Add(GetNUnitDllPath("nunit.framework")); } private static void ConfigureNUnitTest(CodeFixer.Test test) { // Add NUnit assemblies to TestState (for input code compilation) - test.TestState.AdditionalReferences.Add(typeof(NUnit.Framework.TestAttribute).Assembly); - test.TestState.AdditionalReferences.Add(typeof(NUnit.Framework.Legacy.ClassicAssert).Assembly); + test.TestState.AdditionalReferences.Add(GetNUnitDllPath("nunit.framework")); + test.TestState.AdditionalReferences.Add(GetNUnitDllPath("nunit.framework.legacy")); // FixedState: TUnit assemblies only (NO NUnit inheritance) // Use Explicit inheritance mode to prevent NUnit references from being inherited diff --git a/tests/TUnit.Analyzers.Tests/TUnit.Analyzers.Tests.csproj b/tests/TUnit.Analyzers.Tests/TUnit.Analyzers.Tests.csproj index 1cb4aa77c0..4ca7cf56a5 100644 --- a/tests/TUnit.Analyzers.Tests/TUnit.Analyzers.Tests.csproj +++ b/tests/TUnit.Analyzers.Tests/TUnit.Analyzers.Tests.csproj @@ -9,7 +9,7 @@ - + @@ -45,6 +45,16 @@ Link="System.Text.Json.9.0.dll" CopyToOutputDirectory="PreserveNewest" Visible="false" /> + + +