-
-
Notifications
You must be signed in to change notification settings - Fork 110
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
The NUnit migration code fixer (TUNU0001) does not convert NUnit's [FixtureLifeCycle] attribute to TUnit's equivalent, leaving the unconverted attribute in the code which causes compilation errors.
Reproduction Steps
- Create a file with NUnit FixtureLifeCycle attribute:
using NUnit.Framework;
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public class TestClass
{
private int _counter = 0;
[Test]
public void Test1()
{
_counter++;
Assert.That(_counter, Is.EqualTo(1));
}
[Test]
public void Test2()
{
_counter++;
Assert.That(_counter, Is.EqualTo(1));
}
}-
Run the code fixer:
dotnet format analyzers --severity info --diagnostics TUNU0001 -
The attribute remains unconverted:
using System.Threading.Tasks;
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public class TestClass
{
private int _counter = 0;
[Test]
public async Task Test1()
{
_counter++;
await Assert.That(_counter).IsEqualTo(1);
}
[Test]
public async Task Test2()
{
_counter++;
await Assert.That(_counter).IsEqualTo(1);
}
}- Building produces errors:
error CS0246: The type or namespace name 'FixtureLifeCycle' could not be found
error CS0103: The name 'LifeCycle' does not exist in the current context
Expected Behavior
The code fixer should either:
- Convert
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]to TUnit's equivalent (if one exists) - Remove the attribute if TUnit's default behavior matches
InstancePerTestCase - Leave a TODO comment indicating manual migration is required
Environment
- TUnit Version: 1.11.64
- .NET SDK: 10.0.100-preview.1.25103.12
- OS: Windows 11
Additional Context
According to NUnit documentation, [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] creates a new instance of the test fixture for each test method. This is useful for ensuring test isolation.
Note: Please add tests when fixing this issue to prevent regression.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working