-
-
Notifications
You must be signed in to change notification settings - Fork 108
Closed
Description
Summary
The NUnit to TUnit migration code fixer should handle the ExpectedResult property in NUnit test attributes and convert it to TUnit's assertion style.
NUnit Pattern
[TestCase(2, 3, ExpectedResult = 5)]
public int Add(int a, int b)
{
return a + b;
}
[TestCase("hello", ExpectedResult = 5)]
public int GetLength(string input)
{
return input.Length;
}Expected TUnit Output
[Test]
[Arguments(2, 3)]
public async Task Add(int a, int b)
{
await Assert.That(a + b).IsEqualTo(5);
}
[Test]
[Arguments("hello")]
public async Task GetLength(string input)
{
await Assert.That(input.Length).IsEqualTo(5);
}Implementation Notes
- Detect
ExpectedResult = <value>in NUnit attributes ([TestCase],[TestCaseSource], etc.) - Remove
ExpectedResultfrom the migrated[Arguments]attribute - Change method return type from
Ttoasync Task - Wrap the return expression with
await Assert.That(<expr>).IsEqualTo(<expected>) - Handle various return types (int, string, bool, objects, etc.)
Edge Cases to Consider
- Methods with multiple return statements
- Methods with complex return expressions
- Generic return types
- Nullable return types
ExpectedResult = null
Metadata
Metadata
Assignees
Labels
No labels