Skip to content

Document that a single fixture instance is shared by parallel tests - #1278

Open
SeanKilleen wants to merge 1 commit into
masterfrom
292_fixture-instance-lifetime
Open

SeanKilleen wants to merge 1 commit into
masterfrom
292_fixture-instance-lifetime

Conversation

@SeanKilleen

Copy link
Copy Markdown
Member

The Parallelizable page warned about shared instance fields but never stated the underlying fact. Adds a "Fixture Instances and Parallel Tests" section explaining that NUnit creates one instance per fixture (per argument set for parameterized fixtures), constructed before OneTimeSetUp and disposed after OneTimeTearDown, that parallel execution does not create more instances, and that parallel test methods therefore share the same instance. Points to FixtureLifeCycle with InstancePerTestCase as the way to get per-test instances.

Fixes #292

🤖 Generated with Claude Code

The Parallelizable page warned about shared instance fields but never stated the underlying fact. Adds a "Fixture Instances and Parallel Tests" section explaining that NUnit creates one instance per fixture (per argument set for parameterized fixtures), constructed before `OneTimeSetUp` and disposed after `OneTimeTearDown`, that parallel execution does not create more instances, and that parallel test methods therefore share the same instance. Points to `FixtureLifeCycle` with `InstancePerTestCase` as the way to get per-test instances.

Fixes #292

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

Copy link
Copy Markdown

📖 Docs preview: https://pr-1278.nunit-docs.pages.dev

Built from e23fcf5. This link always shows the latest build for this PR; the build for this exact commit is at https://9f0eb246.nunit-docs.pages.dev.

Previews are hosted on Cloudflare Pages, are not indexed by search engines, and are removed when the PR is closed. They omit the archived NUnit 2.x documentation (the /2.x/ pages), which never changes; use the live site for those.

@SeanKilleen

Copy link
Copy Markdown
Member Author

@OsirisTerje who is right person/group to review this?

@OsirisTerje

OsirisTerje commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

@SeanKilleen I think we send it to the @nunit/framework-team 😄

That said, it looks correct to me.

@SeanKilleen
SeanKilleen requested a review from a team November 10, 2026 22:30

## Fixture Instances and Parallel Tests

NUnit creates **one instance** of each test fixture class and reuses it for every test in that fixture. The instance is

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 mention the FixtureLifeCycle and LifeCycle.InstancePerTestCase
It does require static OneTimeSetUp so the sharing of things initialized there is similar.

This branch has not been deployed

No deployments
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.

Unspecified behavior of the Parallelizable Attribute

3 participants