Skip to content

Match MSTest overloads against the test data - #1862

Merged
SimonCropp merged 1 commit into
mainfrom
fix-mstest-overloads
Aug 17, 2026
Merged

Match MSTest overloads against the test data#1862
SimonCropp merged 1 commit into
mainfrom
fix-mstest-overloads

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

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.

FindMethod returned the first method whose name matched, so with overloaded test
methods every case resolved to the same MethodInfo. Two ways that goes wrong:

 * The parameter count guard in BuildVerifier compares the data length against
   that MethodInfo, so it mismatches for the other overload and SetParameters is
   silently skipped, dropping the parameters from the file name.
 * The parameter names handed to InnerVerifier come from that MethodInfo, so a
   same arity overload is labeled with the other overload's parameter names.

The data the test was invoked with is all there is to tell overloads apart, so
candidates are now narrowed by parameter count and then by the types of that
data. It still falls back to the first match when that does not narrow to one.
@SimonCropp SimonCropp added this to the 32.0.0 milestone Aug 17, 2026
@SimonCropp
SimonCropp merged commit 6230c68 into main Aug 17, 2026
7 checks passed
@SimonCropp
SimonCropp deleted the fix-mstest-overloads branch August 17, 2026 12:27
This was referenced Aug 26, 2026
This was referenced Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant