Add support for static test classes - #174
Merged
Merged
Conversation
Changed GetSettingsAttributes to use try-catch blocks with FirstOrDefault to handle cases where xUnit's GetCustomAttributes throws InvalidOperationException for static test classes. Also added test cases for static test classes. Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Added override in UITestRunner to handle static test classes by checking if the class is both Abstract and Sealed (which indicates a static class). For static classes, returns null instance instead of trying to instantiate. Tests now pass for static test classes. Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for static test classes in Xunit.StaFact
Add support for static test classes
Jan 27, 2026
AArnott
approved these changes
Jan 27, 2026
AArnott
marked this pull request as ready for review
January 27, 2026 19:37
Owner
|
@copilot fix all build warnings. Use |
Changed var to Type for @Class variable in CreateTestClassInstance to comply with project's editorconfig rule csharp_style_var_elsewhere = false:warning Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Contributor
Author
Fixed in commit 49a99ad. Changed |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #174 +/- ##
==========================================
- Coverage 71.60% 71.52% -0.09%
==========================================
Files 36 36
Lines 729 748 +19
Branches 62 64 +2
==========================================
+ Hits 522 535 +13
- Misses 186 191 +5
- Partials 21 22 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Aug 24, 2026
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix static test class support in Xunit.StaFact
Plan:
.Single()on GetConstructors() for test class instantiationGetSettingsAttributesmethod inUtilities.csto handle static test classesCreateTestClassInstanceinUITestRunnerto handle static test classesRoot Cause:
The issue was in xUnit v3's
XunitTestRunnerBase.CreateTestClassInstance()method which callsGetConstructors().Single(). For static test classes,GetConstructors()returns an empty array, causing.Single()to throw "Sequence contains no elements".Fix Applied:
GetSettingsAttributesinUtilities.csto use try-catch blocks aroundGetCustomAttributescalls withFirstOrDefault()instead ofSingleOrDefault()CreateTestClassInstanceinUITestRunner.csto detect static test classes (Abstract + Sealed) and return null instance instead of trying to instantiate themTypeinstead ofvarfor @Class variableTest Results:
Security Summary:
No security vulnerabilities were introduced or discovered during this change. The CodeQL security scan found 0 alerts.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.