Add [NoDb] attribute to opt a test out of a database - #1094
Merged
Merged
Conversation
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.
This was referenced Sep 29, 2026
This was referenced Sep 29, 2026
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.
Adds a
[NoDb]attribute so a test in aLocalDbTestBaseclass 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
[PooledDb]on a method in a[NoDb]class still gets a database.[NoDb]test,Databaseis null. AccessingArrangeData,ActDataorAssertData, or callingReset, throws with a message naming[NoDb].[NoDb]with[PooledDb],[SharedDb]or[NewDb]on the same method or class throws. The mutually-exclusive error message now lists[NoDb].Changes
NoDbAttribute, linked into each framework package like the existing attributes.DbAttributeReaderreads four attributes.DbModegainsNone.LocalDbTestBaseskips database setup for[NoDb]tests.NoDbTestsper framework, newDbAttributeReaderTestscases, updated message assertions.All tests in
EfLocalDb.Testsand the four framework test projects pass locally.