Repository navigation
Document load time vs execution time for data sources and custom attributes - #1307
Merged
Merged
Conversation
…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>
|
📖 Docs preview removed because this PR was closed. |
OsirisTerje
approved these changes
Oct 25, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
[SetUp]has no effect.Random, no static side effects.[OneTimeSetUp]/[SetUpFixture]does not exist yet when sources run. Live objects (listeners, subscriptions, services) belong in setup or the test, not in a source.[SetUpFixture]never hears events published to a bus a source created, and the fix. Plus the lazy-initialisation pattern from OneTimeSetUp before TestCaseDataSource? nunit#5036 for state a source and the tests both need.All examples are executable snippets in
Snippets.NUnit/LoadTimeExecutionTimeExamples.csand 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
ITestBuilderandIApplyToTestcan 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 testand .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-cli2andcspell: 0 issues on the changed filesdotnet test docs/snippets/Snippets.slnx: 638 passed, 0 faileddocfx docs/docfx.json: builds with no new warnings; all xrefs resolve🤖 Generated with Claude Code