Skip to content

Commit e732301

Browse files
EvangelinkCopilot
andauthored
Avoid double TestCase construction when filtering during discovery (#9568) (#9665)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 36b8c86 commit e732301

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/Adapter/MSTest.TestAdapter/Services/UnitTestElementSinkExtensions.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public HostDiscoverySink(ITestCaseDiscoverySink discoverySink)
3838
=> _discoverySink = discoverySink;
3939

4040
public void SendTestElement(UnitTestElement testElement)
41-
=> _discoverySink.SendTestCase(testElement.ToTestCase());
41+
=> _discoverySink.SendTestCase(testElement.GetOrCreateHostTestCase());
4242
}
4343
}

‎src/Adapter/MSTest.TestAdapter/TestMethodFilter.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ public TestElementFilter(TestMethodFilter testMethodFilter, ITestCaseFilterExpre
177177

178178
public bool Matches(UnitTestElement testElement)
179179
{
180-
var testCase = testElement.ToTestCase();
180+
// Reuse the element's cached host TestCase so that a matched test is not converted a second time
181+
// when it is subsequently reported to the discovery sink.
182+
TestCase testCase = testElement.GetOrCreateHostTestCase();
181183
return _filterExpression.MatchTestCase(testCase, propertyName => _testMethodFilter.PropertyValueProvider(testCase, propertyName));
182184
}
183185
}

0 commit comments

Comments
 (0)