Skip to content

TUNU0001 code fixer does not remove 'using NUnit.Framework;' directive #4486

@thomhurst

Description

@thomhurst

Description

The TUNU0001 NUnit migration code fixer converts NUnit attributes to TUnit attributes, but does not remove the using NUnit.Framework; directive. This results in CS0246 errors after migration because the NUnit package is typically removed.

Reproduction Steps

  1. Create a test file with NUnit:
using NUnit.Framework;

[TestFixture]
public class MyTests
{
    [Test]
    public void TestMethod()
    {
        Assert.AreEqual(1, 1);
    }
}
  1. Run the TUNU0001 code fixer:
dotnet format analyzers --severity info --diagnostics TUNU0001 --framework net10.0
  1. Remove the NUnit package:
dotnet remove package NUnit
dotnet remove package NUnit3TestAdapter
  1. Build the project

Expected Behavior

The code fixer should remove the using NUnit.Framework; directive along with converting the attributes.

Actual Behavior

The using NUnit.Framework; directive remains, causing CS0246 errors:

error CS0246: The type or namespace name 'NUnit' could not be found

Workaround

Manually remove all using NUnit.Framework; directives:

find . -name "*.cs" -exec sed -i '/using NUnit\.Framework;/d' {} \;

Environment

  • TUnit version: 1.11.64
  • .NET SDK: 10.0.102

Tests should be added to verify the code fixer removes NUnit using directives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions