Skip to content

Document params array support with TestCaseSource - #1276

Merged
SeanKilleen merged 3 commits into
masterfrom
1095_testcasesource-params
Oct 23, 2026
Merged

SeanKilleen merged 3 commits into
masterfrom
1095_testcasesource-params

Conversation

@SeanKilleen

Copy link
Copy Markdown
Member

Optional parameters and CancellationToken injection with TestCaseSource were already documented, but params arrays (the third feature from nunit/nunit#5057, released in 4.5) were not. Adds a short "Params arrays" section explaining how extra source arguments are gathered into the array, what happens with no extra arguments, and that an array of the right type as the last argument is passed through. Backed by a new tested snippet with all four cases.

Fixes #1095

🤖 Generated with Claude Code

Optional parameters and `CancellationToken` injection with `TestCaseSource` were already documented, but `params` arrays (the third feature from nunit/nunit#5057, released in 4.5) were not. Adds a short "Params arrays" section explaining how extra source arguments are gathered into the array, what happens with no extra arguments, and that an array of the right type as the last argument is passed through. Backed by a new tested snippet with all four cases.

Fixes #1095

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

📖 Docs preview removed because this PR was closed.

@SeanKilleen
SeanKilleen requested a review from stevenaw October 22, 2026 15:07

@stevenaw stevenaw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for drafting this @SeanKilleen
This looks good to me, but I'm also going to request review from @manfred-brands for secondary perspective as I think we both changed things in this area in that release

@manfred-brands manfred-brands left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be add a note for the below?

parameters are gathered into that array, just as they are for [TestCase](xref:attribute-testcase). A test case that
supplies no extra arguments gives an empty array, and a test case whose last argument is already an array of the right
type passes it through unchanged. (_NUnit 4.5+_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should say something here or in the CancellationToken section below that these two don't mix.
We cannot declare a CancellationToken parameter after a params array.
Therefore if [CancelAfter] is used with a params array, the user needs to use TestContext.CurrentContext.CancellationToken instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've captured this in the latest commit. Let me know if you agree.

…ection

A params array must be the last parameter, so a test method cannot also
declare the CancellationToken parameter that [CancelAfter] injects. Add a
note to the Params arrays section and a cross-reference in the
CancellationToken section pointing to TestContext.CurrentContext.CancellationToken
as the alternative, backed by a tested snippet.

Addresses review feedback from @manfred-brands.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@manfred-brands manfred-brands left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SeanKilleen
One small change suggestion.

Comment thread docs/snippets/Snippets.NUnit/TestCaseSourceExamples.cs Outdated
Co-authored-by: Manfred Brands <manfred-brands@users.noreply.github.com>
@SeanKilleen
SeanKilleen merged commit 3a359db into master Oct 23, 2026
6 checks passed
@SeanKilleen
SeanKilleen deleted the 1095_testcasesource-params branch October 23, 2026 19:07
github-actions Bot pushed a commit that referenced this pull request Oct 23, 2026
* Document params array support with TestCaseSource

Optional parameters and `CancellationToken` injection with `TestCaseSource` were already documented, but `params` arrays (the third feature from nunit/nunit#5057, released in 4.5) were not. Adds a short "Params arrays" section explaining how extra source arguments are gathered into the array, what happens with no extra arguments, and that an array of the right type as the last argument is passed through. Backed by a new tested snippet with all four cases.

Fixes #1095

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Note that params arrays cannot be combined with CancellationToken injection

A params array must be the last parameter, so a test method cannot also
declare the CancellationToken parameter that [CancelAfter] injects. Add a
note to the Params arrays section and a cross-reference in the
CancellationToken section pointing to TestContext.CurrentContext.CancellationToken
as the alternative, backed by a tested snippet.

Addresses review feedback from @manfred-brands.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* Update docs/snippets/Snippets.NUnit/TestCaseSourceExamples.cs

Co-authored-by: Manfred Brands <manfred-brands@users.noreply.github.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Manfred Brands <manfred-brands@users.noreply.github.com> 3a359db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document support for cancellationtoken, params, and optional arguments with TestCaseSource

3 participants