Skip to content

Fix ConditionalFact not working with new xunit.runner.visualstudio version#15667

Merged
ViktorHofer merged 1 commit intomainfrom
fix-conditionalfact
Mar 25, 2025
Merged

Fix ConditionalFact not working with new xunit.runner.visualstudio version#15667
ViktorHofer merged 1 commit intomainfrom
fix-conditionalfact

Conversation

@akoeplinger
Copy link
Member

@akoeplinger akoeplinger commented Mar 25, 2025

After #15651 I noticed that tests would fail that shouldn't even be executed because of a ConditionalFact that was false.

It turned out that with the new xunit.runner.visualstudio version these tests were always running regardless of the condition.

The reason is that we were setting the _skipReason after calling the base Deserialize(), but that one sets the Timeout property which in turn calls Initialize which calls GetSkipReason() which then calls into our overridden GetSkipReason method in SkippedTestCase and at that point we don't have _skipReason yet so we return null which means the test case is not skipped.

The fix is to set _skipReason before calling the base Deserialize. This is actually exactly what aspnetcore discovered ages ago in dotnet/aspnetcore@b1987c7 / xunit/visualstudio.xunit#266 (comment).

So why did we not notice this until now? It turns out the old version of xunit.runner.visualstudio does not go through the Serialize/Deserialize codepath when running on the command line. If I run with the old version in VS Test Explorer however I see exactly the same issue:

image

The new version seems to use the Serialize/Deserialize protocol also on the command line so that's why we hit it there.

Additionally, the tests in arcade didn't catch this because they were never testing that a ConditionalFact=false method is not executed, only the inverse. Added tests for that scenario too.

It works correctly now both inside and outside of VS with both the old and new version of xunit.runner.visualstudio:
image

akoeplinger added a commit to dotnet/sdk that referenced this pull request Mar 25, 2025
@ViktorHofer ViktorHofer merged commit 8021d75 into main Mar 25, 2025
11 checks passed
@ViktorHofer ViktorHofer deleted the fix-conditionalfact branch March 25, 2025 14:54
dotnet-maestro bot added a commit to dotnet/sdk that referenced this pull request Mar 25, 2025
[main] Update dependencies from dotnet/arcade


 - Remove overriding cert for .msi

arcade now provides the same default.

 - Merge branch 'main' into darc-main-c7b122ee-7487-4482-8d37-948de8d73a9f

 - Add emsdk patch

 - Add backport link

 - Add more patches

 - Update aspire patch

 - Add efcore patch

 - Port dotnet/arcade#15667 to the local TestUtilities copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants