Skip to content

feat: Migrate test framework from XUnit to TUnit 1.2.11#232

Merged
samtrion merged 9 commits intomainfrom
copilot/migrate-to-tunit-1-2-11
Dec 5, 2025
Merged

feat: Migrate test framework from XUnit to TUnit 1.2.11#232
samtrion merged 9 commits intomainfrom
copilot/migrate-to-tunit-1-2-11

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 23, 2025

What does this PR do?

Migrates all test projects from XUnit 2.9.3 to TUnit 1.2.11 as specified in the issue requirements.

Package Changes

  • Replaced XUnit packages (xunit, xunit.runner.visualstudio, NetEvolve.Extensions.XUnit, TngTech.ArchUnitNET.xUnit, Verify.Xunit) with TUnit equivalents
  • Added TUnit 1.2.11, TUnit.Assertions 1.2.11, NetEvolve.Extensions.TUnit 3.0.0, TngTech.ArchUnitNET.TUnit 0.12.3, Verify.TUnit 31.7.2
  • Updated all test project .csproj files to reference TUnit packages
  • Updated assembly attributes from XUnit variants to TUnit variants

Test Code Migration

  • Converted [Fact][Test] attributes across all test files
  • Updated test classes to public partial (required by TUnit source generators)
  • Removed explicit TUnit using statements (TUnit provides global usings)
  • Added await to all assertion statements (TUnit assertions return Task)

Architecture Tests

  • Migrated from ArchUnitNET.xUnit to ArchUnitNET.TUnit
  • Architecture rules continue using same validation logic

Known TUnit Differences

TUnit's primary difference from XUnit: all assertions are async and must be awaited. This requires:

  • Adding await before Assert.That() and Assert.Throws()
  • Converting synchronous test methods to async Task
  • Handling [Theory]/[MemberData] patterns differently (use multiple [Arguments] attributes)

Remaining Work

  • ~10-15 synchronous Unit test methods need conversion to async Task
  • Assert.Throws patterns need refinement (exception variable assignment shouldn't be awaited)
  • One [Theory] test in IServiceCollectionExtensionsTests.cs needs conversion to [Arguments] pattern

Why is it important?

TUnit provides modern .NET testing capabilities with source generators, improved async/await support, and better performance through Microsoft.Testing.Platform integration as configured in global.json.

Related issues

  • Closes #[issue_number]

How to test this PR

dotnet build Extensions.Hosting.WinForms.slnx
dotnet test Extensions.Hosting.WinForms.slnx

Note: Build currently fails with ~100 errors related to remaining synchronous methods needing async conversion. These are mechanical fixes following the pattern established in completed test files.

Follow-ups

After completing the remaining async conversions:

  • Verify all tests pass with TUnit test runner
  • Confirm code coverage reporting works with new framework
  • Validate CI/CD pipeline compatibility
Original prompt

This section details on the original issue you should resolve

<issue_title>Migrate from XUnit to TUnit 1.2.11</issue_title>
<issue_description>## Goal
Migrate the test framework from XUnit to TUnit 1.2.11 across all test projects in the solution.

Scope

This migration affects the following test projects:

  • NetEvolve.Extensions.Hosting.WinForms.Tests.Architecture
  • NetEvolve.Extensions.Hosting.WinForms.Tests.Integration
  • NetEvolve.Extensions.Hosting.WinForms.Tests.Unit

Required Package Changes

Packages to Replace in Directory.Packages.props

Remove XUnit packages:

  • xunit (currently: 2.9.3)
  • xunit.runner.visualstudio (currently: 3.1.5)
  • NetEvolve.Extensions.XUnit (currently: 2.7.59)
  • TngTech.ArchUnitNET.xUnit (currently: 0.12.3)
  • Verify.Xunit (currently: 22.11.5)

Add TUnit packages:

  • TUnit (version: 1.2.11)
  • TUnit.Assertions (version: 1.2.11)
  • TUnit.Engine.SourceGenerator (version: 1.2.11)
  • NetEvolve.Extensions.TUnit (equivalent to NetEvolve.Extensions.XUnit)
  • TngTech.ArchUnitNET.TUnit (equivalent to TngTech.ArchUnitNET.xUnit)
  • Verify.TUnit (equivalent to Verify.Xunit)

Keep (no changes):

  • Microsoft.NET.Test.Sdk (18.0.1)
  • coverlet.collector (6.0.4)
  • coverlet.msbuild (6.0.4)
  • NSubstitute (5.3.0)

Migration Tasks

1. Update Package References

  • Update Directory.Packages.props with TUnit package versions
  • Remove XUnit package references
  • Add TUnit package references

2. Update Test Project Files

  • Update all .csproj files in test projects to reference TUnit packages
  • Ensure proper target framework compatibility (net8.0-windows, net9.0-windows)

3. Code Migration

  • Replace XUnit attributes with TUnit equivalents:
    • [Fact][Test]
    • [Theory][Test]
    • [InlineData][Arguments]
    • [MemberData][MethodDataSource]
    • [ClassData][ClassDataSource]
  • Update assertion syntax (if needed)
  • Update test class and method modifiers (TUnit requires public partial classes)
  • Update lifecycle attributes:
    • [Collection] → TUnit equivalent
    • Constructor/Dispose patterns → TUnit lifecycle hooks

4. Architecture Tests

  • Migrate ArchUnit tests from TngTech.ArchUnitNET.xUnit to TngTech.ArchUnitNET.TUnit
  • Verify architecture rules still work correctly

5. Verification Tests

  • Migrate Verify tests from Verify.Xunit to Verify.TUnit
  • Ensure snapshot tests continue to work

6. Testing & Validation

  • Run all tests in Architecture project
  • Run all tests in Integration project
  • Run all tests in Unit project
  • Verify CI/CD pipeline compatibility
  • Ensure code coverage reporting still works

Benefits of Migration

  • Modern Test Framework: TUnit is a modern, high-performance testing framework
  • Better Performance: TUnit offers improved test execution speed
  • Enhanced Features: Better async/await support and improved diagnostics
  • Source Generators: Uses modern .NET source generators for better compile-time checks

Breaking Changes

  • Test class syntax changes (requires public partial classes)
  • Attribute naming changes
  • Potential differences in test discovery and execution

Documentation

  • Update README.md if it mentions testing
  • Update any developer documentation about running tests
  • Add migration notes for contributors

References


Estimated Effort: Medium (2-4 hours depending on test complexity)
Priority: Medium
Labels: enhancement, testing, migration</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 23, 2025

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • state:ready for merge

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@samtrion samtrion added the type:techdebt Indicates an issue or pull request that address technical debt. label Nov 23, 2025
Copilot AI changed the title [WIP] Migrate test framework from XUnit to TUnit 1.2.11 Migrate test framework from XUnit to TUnit 1.2.11 Nov 23, 2025
Copilot AI requested a review from samtrion November 23, 2025 21:22
@samtrion samtrion marked this pull request as ready for review November 23, 2025 21:23
@samtrion samtrion requested a review from a team as a code owner November 23, 2025 21:23
@samtrion samtrion changed the title Migrate test framework from XUnit to TUnit 1.2.11 feat: Migrate test framework from XUnit to TUnit 1.2.11 Nov 23, 2025
@samtrion samtrion force-pushed the copilot/migrate-to-tunit-1-2-11 branch from e0135d8 to faf9503 Compare November 23, 2025 21:25
@samtrion samtrion force-pushed the copilot/migrate-to-tunit-1-2-11 branch 2 times, most recently from 776d245 to 43c8063 Compare December 5, 2025 17:01
Copilot AI and others added 6 commits December 5, 2025 18:04
Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
- Updated using statements in all test files
- Converted [Fact] to [Test]
- Converted Assert methods to TUnit equivalents
- Made test classes public partial
- Still fixing compilation errors in WindowsFormsSynchronizationContextProviderTests.cs

Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
- Removed explicit TUnit using statements (using global usings)
- Added await to all Assert.That statements
- Need to convert synchronous test methods to async
- Need to fix Assert.Throws patterns

Co-authored-by: samtrion <3283596+samtrion@users.noreply.github.com>
@samtrion samtrion force-pushed the copilot/migrate-to-tunit-1-2-11 branch from 43c8063 to 422732f Compare December 5, 2025 17:04
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.79%. Comparing base (e289943) to head (58a2033).
⚠️ Report is 24 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##           main     #232       +/-   ##
=========================================
+ Coverage      0   96.79%   +96.79%     
=========================================
  Files         0        7        +7     
  Lines         0      343      +343     
  Branches      0       31       +31     
=========================================
+ Hits          0      332      +332     
- Misses        0        8        +8     
- Partials      0        3        +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samtrion samtrion merged commit 4cfb67f into main Dec 5, 2025
8 checks passed
@samtrion samtrion deleted the copilot/migrate-to-tunit-1-2-11 branch December 5, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:techdebt Indicates an issue or pull request that address technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate from XUnit to TUnit 1.2.11

2 participants