Skip to content

Code fixer converts [Platform] attribute to non-existent [ExcludeOn(OS.X)] attribute #4489

@thomhurst

Description

@thomhurst

Description

The NUnit migration code fixer (TUNU0001) converts NUnit's [Platform] attribute to [ExcludeOn(OS.X)], but neither the ExcludeOn attribute nor the OS enum exist in TUnit. This results in compilation errors.

Reproduction Steps

  1. Create a file with NUnit Platform attributes:
using NUnit.Framework;

public class TestClass
{
    [Test]
    [Platform(Exclude = "Mono")]
    public void Test_ExcludeMono() { }

    [Test]
    [Platform(Exclude = "Net")]
    public void Test_ExcludeNet() { }

    [Test]
    [Platform(Exclude = "Net,NetCore")]
    public void Test_ExcludeNetAndNetCore() { }
}
  1. Run the code fixer: dotnet format analyzers --severity info --diagnostics TUNU0001

  2. The code is converted to:

using System.Threading.Tasks;

public class TestClass
{
    [Test]
    [ExcludeOn(OS.Mono)]
    public async Task Test_ExcludeMono() { }

    [Test]
    [ExcludeOn(OS.Net)]
    public async Task Test_ExcludeNet() { }

    [Test]
    [ExcludeOn(OS.Net | OS.NetCore)]
    public async Task Test_ExcludeNetAndNetCore() { }
}
  1. Building produces errors:
error CS0246: The type or namespace name 'ExcludeOn' could not be found
error CS0103: The name 'OS' does not exist in the current context

Expected Behavior

The code fixer should either:

  1. Convert Platform attributes to TUnit's equivalent skip mechanism (custom SkipAttribute)
  2. Leave a TODO comment indicating manual migration is required
  3. Not convert the attribute at all if no direct equivalent exists

Environment

  • TUnit Version: 1.11.64
  • .NET SDK: 10.0.100-preview.1.25103.12
  • OS: Windows 11

Additional Context

TUnit's recommended approach for platform-specific test skipping is to create custom skip attributes by extending SkipAttribute. The code fixer is generating references to types that don't exist in TUnit.


Note: Please add tests when fixing this issue to prevent regression.

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