Skip to content

Guard TUnit parameter binding and null TestContext - #1894

Merged
SimonCropp merged 1 commit into
mainfrom
fix-tunit-params-and-context
Aug 29, 2026
Merged

Guard TUnit parameter binding and null TestContext#1894
SimonCropp merged 1 commit into
mainfrom
fix-tunit-params-and-context

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

Two fixes in the same method, sharing one helper.

TestMethodArguments holds the raw pre-binding arguments: TUnit bundles a params array at invocation time. SetParameters was called with them unconditionally, so a [Arguments(1, 2, 3)] test with a params int[] parameter ran fine under TUnit but threw 'The number of passed in parameters (3) must not exceed the number of parameters for the method (1)' from every Verify call. The argument count is now compared with the parameter name count first, matching MSTest and XunitV3.

TestContext.Current is nullable, and is null in a [Before(TestSession)] hook or any code that does not flow the test context. Both BuildVerifier and VerifyChecks.Run dereferenced it with !, giving a bare NullReferenceException. They now throw the same kind of explanatory error the other adapters do.

Two fixes in the same method, sharing one helper.

TestMethodArguments holds the raw pre-binding arguments: TUnit bundles a params
array at invocation time. SetParameters was called with them unconditionally, so
a [Arguments(1, 2, 3)] test with a params int[] parameter ran fine under TUnit
but threw 'The number of passed in parameters (3) must not exceed the number of
parameters for the method (1)' from every Verify call. The argument count is now
compared with the parameter name count first, matching MSTest and XunitV3.

TestContext.Current is nullable, and is null in a [Before(TestSession)] hook or
any code that does not flow the test context. Both BuildVerifier and
VerifyChecks.Run dereferenced it with !, giving a bare NullReferenceException.
They now throw the same kind of explanatory error the other adapters do.
@SimonCropp SimonCropp added this to the 33.0.0 milestone Aug 29, 2026
@SimonCropp
SimonCropp merged commit a2d1a6c into main Aug 29, 2026
6 of 7 checks passed
@SimonCropp
SimonCropp deleted the fix-tunit-params-and-context branch August 29, 2026 10:36
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