Skip to content

Code fix for NUnit2055 can generate invalid code for classic asserts #953

@philipp-naused

Description

@philipp-naused
[Test]
public void SampleTest()
{
    object value = "Hello, World!";
    ClassicAssert.IsTrue(value is string);
}

This code will trigger two warnings:
NUnit2003: Consider using the constraint model, Assert.That(expr, Is.True), instead of the classic model, ClassicAssert.IsTrue(expr)
NUnit2055: Consider using Is.InstanceOf<string> instead of 'is string' expression for better assertion messages

I have this as .editorconfig to turn them both into warnings:

[*.cs]
dotnet_analyzer_diagnostic.category-Assertion.severity = warning

If I apply all code fixes (dotnet format), NUnit2055 will be applied first and generate this:

ClassicAssert.IsTrue(value, Is.InstanceOf<string>());

which doesn't compile...

If I explicitly tell it to fix NUnit2003 first, this doesn't happen.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions