Skip to content

Add [NoDb] attribute to opt a test out of a database - #1094

Merged
SimonCropp merged 3 commits into
mainfrom
no-db-attribute
Sep 29, 2026
Merged

SimonCropp merged 3 commits into
mainfrom
no-db-attribute

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Adds a [NoDb] attribute so a test in a LocalDbTestBase class can opt out of a database without being moved to a separate class.

Why

A test with no attribute falls back to a new database per test, the most expensive mode. Rendering, formatting and validation tests often sit next to related database tests but never touch the database, and currently pay the full cost. Splitting them into a separate class works, but moves their Verify snapshots and scatters related tests.

Behavior

  • Applies to a test method or class. The nearest attribute wins, so [PooledDb] on a method in a [NoDb] class still gets a database.
  • In a [NoDb] test, Database is null. Accessing ArrangeData, ActData or AssertData, or calling Reset, throws with a message naming [NoDb].
  • Combining [NoDb] with [PooledDb], [SharedDb] or [NewDb] on the same method or class throws. The mutually-exclusive error message now lists [NoDb].
  • Supported in the MSTest, NUnit, TUnit and xunit.v3 packages.

Changes

  • NoDbAttribute, linked into each framework package like the existing attributes.
  • DbAttributeReader reads four attributes. DbMode gains None.
  • Each LocalDbTestBase skips database setup for [NoDb] tests.
  • Tests: NoDbTests per framework, new DbAttributeReaderTests cases, updated message assertions.
  • Docs: "NoDb" section on each framework usage page, and a note on the test strategy page.
  • Version bumped to 27.2.0.

All tests in EfLocalDb.Tests and the four framework test projects pass locally.

SimonCropp and others added 3 commits September 29, 2026 14:12
Tests in a LocalDbTestBase class that do not touch the database (rendering,
formatting, validation) currently get a new database per test by default,
the most expensive mode. [NoDb] on a method or class skips building one.
Database is null, and ArrangeData, ActData, AssertData and Reset throw.

Supported in the MSTest, NUnit, TUnit and xunit.v3 packages. Bump to 27.2.0.
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.

2 participants