Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.19.1" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.19.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.19.0" />
<PackageVersion Include="NUnit" Version="4.6.1" />
<PackageVersion Include="NUnit" Version="5.0.0" />
Comment thread
thomhurst marked this conversation as resolved.
<PackageVersion Include="NUnit.Analyzers" Version="4.15.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="6.3.0" />
<PackageVersion Include="OneOf" Version="3.0.271" />
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/migration/nunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ await Assert.That(text).EndsWith(suffix);
```csharp
// NUnit
Assert.Throws<InvalidOperationException>(() => DoSomething());
Assert.ThrowsAsync<InvalidOperationException>(async () => await DoSomethingAsync());
await Assert.ThrowsAsync<InvalidOperationException>(async () => await DoSomethingAsync()); // NUnit 3/4: not awaited

// TUnit
Assert.Throws<InvalidOperationException>(() => DoSomething());
Expand Down
4 changes: 3 additions & 1 deletion src/TUnit.Analyzers/Migrators/NUnitMigrationAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
22 changes: 19 additions & 3 deletions tests/TUnit.Analyzers.Tests/NUnitMigrationAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion tests/TUnit.Analyzers.Tests/TUnit.Analyzers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageReference Include="Microsoft.Testing.Extensions.HangDump" />
<PackageReference Include="Polly" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit" GeneratePathProperty="true" />
<PackageReference Include="xunit.v3.extensibility.core" />
<PackageReference Include="xunit.v3.assert" />
<PackageReference Include="System.Text.Json" Condition="'$(TargetFramework)' == 'net8.0'" GeneratePathProperty="true" PrivateAssets="all" />
Expand Down Expand Up @@ -45,6 +45,16 @@
Link="System.Text.Json.9.0.dll"
CopyToOutputDirectory="PreserveNewest"
Visible="false" />
<!-- NUnit 5 ships a net10.0 build that references System.Runtime 10.0; referencing it from
the Net90 analyzer-test compilation raises CS1705. Use NUnit's net8.0 build instead. -->
<None Include="$(PkgNUnit)\lib\net8.0\nunit.framework.dll"
Link="nunit.framework.net8.0.dll"
CopyToOutputDirectory="PreserveNewest"
Visible="false" />
<None Include="$(PkgNUnit)\lib\net8.0\nunit.framework.legacy.dll"
Link="nunit.framework.legacy.net8.0.dll"
CopyToOutputDirectory="PreserveNewest"
Visible="false" />
<Compile Include="..\SharedTestHelpers\AnalyzerTestCompatibility.cs"
Link="Shared\AnalyzerTestCompatibility.cs" />
<Compile Include="..\SharedTestHelpers\RulesDecouplingVerifier.cs"
Expand Down
4 changes: 2 additions & 2 deletions tools/TUnit.DocSnippetGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ static void AppendFrameworkAliases(StringBuilder builder, Snippet snippet)
.AppendLine("using ValuesAttribute = global::NUnit.Framework.ValuesAttribute;")
.AppendLine("using RangeAttribute = global::NUnit.Framework.RangeAttribute;")
.AppendLine("using TestContext = global::NUnit.Framework.TestContext;")
.AppendLine("using CollectionAssert = global::NUnit.Framework.Legacy.CollectionAssert;")
.AppendLine("using StringAssert = global::NUnit.Framework.Legacy.StringAssert;")
.AppendLine("using CollectionAssert = global::NUnit.Framework.CollectionAssert;")
.AppendLine("using StringAssert = global::NUnit.Framework.StringAssert;")
.AppendLine("using Is = global::NUnit.Framework.Is;")
.AppendLine("using Does = global::NUnit.Framework.Does;")
.AppendLine("using Has = global::NUnit.Framework.Has;");
Expand Down
Loading