Skip to content

Code fixer TUXU0001 leaves merge conflict markers in code during xUnit migration #4612

@thomhurst

Description

@thomhurst

Description

The TUnit xUnit migration code fixer (diagnostic TUXU0001) is leaving merge conflict markers in the code during automatic migration, causing compilation errors.

Environment

  • TUnit Version: 1.12.90
  • .NET SDK: 10.0.100
  • Original Testing Framework: xUnit 2.9.3
  • Target Frameworks: net472, net8.0
  • Language Version: C# 12.0

Reproduction Steps

  1. Create or clone a project with xUnit tests (tested with https://github.com/devlooped/moq - Moq.Tests project)
  2. Add TUnit package: dotnet add package TUnit
  3. Temporarily disable implicit usings in .csproj:
    <TUnitImplicitUsings>false</TUnitImplicitUsings>
    <TUnitAssertionsImplicitUsings>false</TUnitAssertionsImplicitUsings>
  4. Run the code fixer: dotnet format analyzers --severity info --diagnostics TUXU0001 --framework net8.0

Expected Behavior

The code fixer should automatically convert xUnit assertions to TUnit assertions without leaving merge conflict markers.

Actual Behavior

The code fixer leaves merge conflict markers in the code like:

<<<<<<< TODO: Unmerged change from project 'Moq.Tests(net8.0)', Before:
Assert.NotEqual(mock1.Object.GetHashCode(), mock2.Object.GetHashCode());
=======
Assert.NotEqual(mock2.Object.GetHashCode());
>>>>>>> After
await Assert.That(mock1.Object.GetHashCode()).IsEqualTo(mock1.Object.GetHashCode());

Impact

  • Compilation fails with CS8300 errors: "Merge conflict marker encountered"
  • Additional cascading syntax errors due to incomplete code
  • Affects 2 files in the test project with 23 total merge conflict markers
  • Files affected: MockFixture.cs (4 markers), Regressions/IssueReportsFixture.cs (19 markers)

Assertion Patterns Affected

The issue appears when converting:

  • Assert.Equal(expected, actual) with two arguments
  • Assert.NotEqual(expected, actual) with two arguments
  • Potentially other multi-argument assertions

Workaround

Manual removal of merge conflict markers and correction of the generated assertions is required.

Additional Context

According to the migration guide at https://tunit.dev/docs/migration/xunit, the code fixer should handle "80-90% of typical test suites automatically." This bug significantly impacts the automated migration experience.

The project being migrated is the Moq library test suite, which contains extensive xUnit tests, making it a good real-world test case for the migration tooling.

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