Match MSTest overloads against the test data

Merged
SI
3mo ago
+142-4

TestExecutionContext.FindMethod returned the first method whose name matched TestContext.TestName, ignoring parameters. With overloaded test methods every case resolved to the same MethodInfo, which goes wrong two ways — both reproduced:

  • Parameters dropped. BuildVerifier only calls SetParameters when the test data length matches that MethodInfo's parameter count, so for the other overload it silently does not. Overload(int, int) with [DataRow(1, 2)] named its snapshot OverloadTests.Overload.verified.txt — no parameters at all, so every case of that overload collides on one file.
  • Wrong parameter names. The names handed to InnerVerifier come from that same MethodInfo, so a same-arity overload is labeled with the other overload's parameter names. SameArityOverload(int number) with [DataRow(1)] named its snapshot ..._text=1, borrowing text from the string overload.

The data the test was invoked with is all there is to tell overloads apart, so candidates are now narrowed by parameter count (allowing for a params array, whose DataRow exposes raw pre-binding data) and then by the runtime types of that data. When neither narrows to a single candidate it falls back to the first match, so nothing that resolves today changes.

The non-overloaded path is unchanged: a single name match returns immediately, without allocating the candidate list.

OverloadTests covers both shapes — different arity, and same arity distinguishable only by type. Both produce wrong names on main.

Verify.MSTest.Tests passes for net11.0 and net48 (163), and Verify.MSTest builds for all seven target frameworks.