diff --git a/Directory.Packages.props b/Directory.Packages.props
index 5ac3b6fb255..6ba4e051d7d 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -83,7 +83,7 @@
-
+
diff --git a/docs/docs/migration/nunit.md b/docs/docs/migration/nunit.md
index e904b30a44f..05dbf51fb38 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 861c0c584dc..5705eba6274 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 21c4c220583..7762fe1f93d 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 1cb4aa77c0b..4ca7cf56a52 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" />
+
+
+