Skip to content

TUXU0001: Partial file conversion leaves project in broken mixed state #4420

@thomhurst

Description

@thomhurst

Description

When running the xUnit migration code fixer on a project with multiple test files, some files are converted while others are not. This leaves the project in a broken state where:

  1. Some files have TUnit syntax ([Test], await Assert.That())
  2. Other files still have xUnit syntax ([Fact], Assert.Equal())
  3. Both xUnit and TUnit packages are referenced
  4. Enabling TUnit implicit usings causes ambiguous reference errors in unconverted files
  5. Disabling implicit usings causes missing type errors in converted files

Steps to Reproduce

  1. Create a test project with 50+ xUnit test files
  2. Add TUnit package reference
  3. Run dotnet format analyzers --severity info --diagnostics TUXU0001
  4. Observe partial conversion

Observed Behavior

In my test case with ~85 test files:

  • ~54 files (~63%) were converted to TUnit syntax
  • ~31 files (~37%) were NOT converted at all

The unconverted files still have:

  • using Xunit;
  • [Fact] attributes
  • Assert.Equal(), Assert.True(), etc.

The Broken State

With TUnit Implicit Usings Enabled

<TUnitImplicitUsings>true</TUnitImplicitUsings>

Result:

  • Converted files work but unconverted files fail:
error CS0104: 'Assert' is an ambiguous reference between 'TUnit.Assertions.Assert' and 'Xunit.Assert'

With TUnit Implicit Usings Disabled

<TUnitImplicitUsings>false</TUnitImplicitUsings>

Result:

  • Unconverted files might work but converted files fail:
error CS0246: The type or namespace name 'Test' could not be found

Expected Behavior

The code fixer should either:

  1. Convert ALL files in a project when run in project/solution scope (Fix All)
  2. Clearly report which files couldn't be converted and why
  3. Not leave the project in a broken, inconsistent state

Impact

This partial conversion issue makes the migration process extremely difficult because:

  1. Users cannot simply run the code fixer and have a working project
  2. Manual intervention is required to fix hundreds/thousands of compilation errors
  3. It's unclear which files need manual attention
  4. The error messages don't indicate whether the issue is with xUnit remnants or TUnit migration

Suggested Fix

  1. Priority: Fix the "Fix All" action (see issue TUXU0001: XUnitMigrationCodeFixProvider Fix All action not working #4416) so all files are converted
  2. Add diagnostic output listing files that couldn't be converted
  3. Add a validation pass after conversion that ensures no mixed state exists
  4. Consider atomic conversion - either convert all files or roll back changes

Workaround (for users)

Until this is fixed, users must:

  1. Run the code fixer
  2. Manually identify unconverted files: grep -l "\[Fact\]" **/*.cs
  3. Manually convert or run the code fixer file-by-file on remaining files
  4. Or remove xUnit package and fix all errors manually

Environment

  • TUnit Version: 1.11.*
  • .NET SDK: 10.0.102
  • OS: Windows

Related Issues

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