dotnet/roslyn-sdk

NUnit 4.0 Breaks Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit

JasonBock opened this issue ยท 14 comments

I updated one of my projects to use NUnit 4.0.0-beta.1, and when I ran my tests, I got an odd MissingMethodException, because somewhere within Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit, it's trying to call Assert.AreEqual(). This method no longer exists in NUnit 4 and was moved to a separate package in a new class, ClassicAssert. I can get around this by not upgrading to NUnit 4, but....I'm guessing the only real way to fix this is that someone will need to update the code in Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit to use a different assertion.

FWIW I'm referencing 1.1.1 of Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit

More info: https://docs.nunit.org/articles/nunit/Towards-NUnit4.html

Now that the fix is merged, when will it be released? ๐Ÿค”

@CodingFlow it looks like there is an error in our publishing pipeline that needs to be resolved. The publish should be automatic once that is fixed.

Hi @sharwell, any news regarding your publishing pipeline ? ๐Ÿ™‚

Should be fixed now with build 1.1.2-beta1.23621.2

I hit the same problem yesterday and had to downgrade nunit to 3 for it. Does anyone know when it will be released?

@sangwei Are you able to test 1.1.2-beta1.23621.2 or newer?

Note that this package is published to the dotnet-tools feed:

<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />

Is this going non-beta anytime soon?

@sharwell for some reasons, it still happens:

image

used versions:

    <PackageVersion Include="Microsoft.CodeAnalysis" Version="4.8.0" />
    <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
    <PackageVersion Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.1.2-beta1.24074.2" />
    <PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
    <PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing " Version="1.1.2-beta1.24074.2" />
    <PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.NUnit " Version="1.1.2-beta1.24074.2" />
    <PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit" Version="1.1.2-beta1.24074.2" />
    <PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
    <PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
    <PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
    <PackageVersion Include="NUnit" Version="4.0.1" />
    <PackageVersion Include="NUnit.Analyzers" Version="3.10.0" />
    <PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />

Implementation of NotEmpty looks like this:

        public virtual void NotEmpty<T>(string collectionName, IEnumerable<T> collection)
        {
            Assert.That(collection, Is.Not.Empty, CreateMessage($"expected '{collectionName}' to be non-empty, contains"));
        }

@jasonmalinowski with two of three frameworks broken now, maybe it's time to take the approach of #1144 for all of them.

I'm having the same issue as @juwens described above - could we reopen this issue?

@lucahost The plan I'm working for is removing the NuGet package altogether. Users can adopt this approach at any time by removing the .NUnit suffixes from the testing package references, and using DefaultVerifier instead of NUnitVerifier.

@lucahost The plan I'm working for is removing the NuGet package altogether. Users can adopt this approach at any time by removing the .NUnit suffixes from the testing package references, and using DefaultVerifier instead of NUnitVerifier.

It's working for me by using DefaultVerifier instead of NUnitVerifier, but I can't remove the Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit package without getting compile errors:

image

@CodingFlow When removing Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.NUnit, you would need to add Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.