Skip to content

Document load time vs execution time for data sources and custom attributes - #1307

Merged
SeanKilleen merged 1 commit into
masterfrom
1258_load-time-vs-execution-time
Oct 26, 2026
Merged

SeanKilleen merged 1 commit into
masterfrom
1258_load-time-vs-execution-time

Conversation

@SeanKilleen

Copy link
Copy Markdown
Member

Closes #1258. Follows up on the discussion in #995 and #996.

What this adds

A shared page: Load Time and Execution Time (under Writing Tests), which states plainly:

All examples are executable snippets in Snippets.NUnit/LoadTimeExecutionTimeExamples.cs and pass.

Custom Attributes page reworked so the load-time / execution-time grouping explains its consequences rather than just listing the interfaces, with a "Rules for attribute authors" section: don't keep state on attribute instances (an attribute implementing both ITestBuilder and IApplyToTest can be two separate objects, since NUnit fetches them through separate reflection calls), builders must be repeatable, create live objects at execution time, don't assume a single load.

Adapter docs: new "Discovery and execution" section on the Usage page covering RTD on, RTD off, dotnet test and .NET Framework AppDomains, with the practical consequences (never expect discovery state at execution; [Random] is safe because the adapter saves and restores the seed; PreFilter).

Links from the data-source pages: TestCaseSource (extends the existing "no communication between load and execution phases" paragraph as suggested, rather than duplicating it), ValueSource (also drops the outdated "non-static sources" wording), TestFixtureSource, DatapointSource and Random, plus Data Driven Tests, Preparing and Cleaning Up Tests and the Parameterized Tests technical note.

Verification

  • markdownlint-cli2 and cspell: 0 issues on the changed files
  • dotnet test docs/snippets/Snippets.slnx: 638 passed, 0 failed
  • docfx docs/docfx.json: builds with no new warnings; all xrefs resolve

🤖 Generated with Claude Code

…ibutes

Adds a shared "Load Time and Execution Time" guide page explaining that the
test tree, including every argument, is built when the assembly is loaded
and cannot change during execution; that arguments are never copied or
marshalled; that load-time code can run more than once and must be
repeatable; and that live objects belong in setup, not in data sources.
Includes the event-bus scenario from #996 as a worked example, with tested
snippets for the problem, the fix, and the lazy-initialisation workaround
from nunit/nunit#5036.

Reworks the Custom Attributes page so the load-time/execution-time grouping
explains its consequences and adds rules for attribute authors (no state on
attribute instances, repeatable builders, live objects at execution time).

Adds a "Discovery and execution" section to the adapter Usage page covering
how often the assembly is loaded with RTD on, with RTD off, under
dotnet test and on .NET Framework, and links to the shared page from
TestCaseSource, ValueSource, TestFixtureSource, DatapointSource, Random,
Data Driven Tests, Preparing and Cleaning Up Tests and Parameterized Tests.

Closes #1258

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

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

📖 Docs preview removed because this PR was closed.

@SeanKilleen
SeanKilleen merged commit f232fa3 into master Oct 26, 2026
6 checks passed
@SeanKilleen
SeanKilleen deleted the 1258_load-time-vs-execution-time branch October 26, 2026 01:00
github-actions Bot pushed a commit that referenced this pull request Oct 26, 2026
…ibutes (#1307)

Adds a shared "Load Time and Execution Time" guide page explaining that the
test tree, including every argument, is built when the assembly is loaded
and cannot change during execution; that arguments are never copied or
marshalled; that load-time code can run more than once and must be
repeatable; and that live objects belong in setup, not in data sources.
Includes the event-bus scenario from #996 as a worked example, with tested
snippets for the problem, the fix, and the lazy-initialisation workaround
from nunit/nunit#5036.

Reworks the Custom Attributes page so the load-time/execution-time grouping
explains its consequences and adds rules for attribute authors (no state on
attribute instances, repeatable builders, live objects at execution time).

Adds a "Discovery and execution" section to the adapter Usage page covering
how often the assembly is loaded with RTD on, with RTD off, under
dotnet test and on .NET Framework, and links to the shared page from
TestCaseSource, ValueSource, TestFixtureSource, DatapointSource, Random,
Data Driven Tests, Preparing and Cleaning Up Tests and Parameterized Tests.

Closes #1258

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> f232fa3
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 load-time vs execution-time constraints for test data sources and custom attributes

2 participants