Skip to content

Commit dcc4678

Browse files
committed
Filter out duplicate test warnings caused by Test Explorer passing duplicates when multi-targeting
1 parent 3ae7409 commit dcc4678

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/xunit.runner.visualstudio/VsTestRunner.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public void RunTests(
395395
runContext, frameworkHandle, logger, testPlatformContext, runSettings,
396396
() =>
397397
tests
398+
.Distinct(TestCaseUniqueIDComparer.Instance)
398399
.GroupBy(testCase => testCase.Source)
399400
.Select(group => AssemblyRunInfo.Create(logger, project, runSettings, group.Key, [.. group], runExplicitTests))
400401
.WhereNotNull()
@@ -692,5 +693,34 @@ class DiscoveredTestCase(
692693

693694
public string UniqueID { get; } = testCase.TestCaseUniqueID;
694695
}
696+
697+
class TestCaseUniqueIDComparer : IEqualityComparer<TestCase>
698+
{
699+
public static TestCaseUniqueIDComparer Instance = new();
700+
701+
public bool Equals(TestCase? x, TestCase? y)
702+
{
703+
if (x is null)
704+
return y is null;
705+
if (y is null)
706+
return false;
707+
if (x.GetPropertyValue(TestCaseUniqueIDProperty) is not string xID)
708+
return false;
709+
if (y.GetPropertyValue(TestCaseUniqueIDProperty) is not string yID)
710+
return false;
711+
712+
return xID == yID;
713+
}
714+
715+
public int GetHashCode(TestCase obj)
716+
{
717+
if (obj is null)
718+
return 0;
719+
if (obj.GetPropertyValue(TestCaseUniqueIDProperty) is not string id)
720+
return 0;
721+
722+
return id.GetHashCode();
723+
}
724+
}
695725
}
696726
}

0 commit comments

Comments
 (0)