Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guidance on testing EF Core apps #2216

Merged
merged 3 commits into from
Mar 24, 2020
Merged

Conversation

ajcvickers
Copy link
Member

Part of #1304 and #430

@ajcvickers ajcvickers requested a review from a team March 24, 2020 16:36
So if you do use SQLite for some testing, make sure to also test against your real database system.

See [Testing with SQLite](xref:core/miscellaneous/testing/sqlite) for EF Core specific guidance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most developers use in-memory instead of relational for perf reasons, so we should gives some tips how to speed it up. Assuming most of the time is spent creating the database/schema:

  • Write tests that don't change the database or are wrapped in a transaction that is rolled back after the test is finished.
  • Clean the database data instead of recreating the schema. See SqlServerDatabaseCleaner.cs for a generic way of how to do this.
  • Create multiple copies of the database and assign one per test class to be able to run the tests in parallel

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I have been sample tests and had similar thoughts. I think I'll create a new document for this to go alongside the updated docs for SQLite and in-memory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do this in another PR.


Instead we use the in-memory database when unit testing something that uses DbContext.
In this case using the in-memory database is appropriate because the test is not dependent on database behavior.
Just don't do this to test actual database queries or updates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ambiguous what "this" is referring to. In general this sentence is low value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will re-word or remove in next PR.

ajcvickers and others added 2 commits March 24, 2020 15:11
Co-Authored-By: Andriy Svyryd <AndriySvyryd@users.noreply.github.com>
Co-Authored-By: Andriy Svyryd <AndriySvyryd@users.noreply.github.com>
@ajcvickers ajcvickers merged commit e6a378f into master Mar 24, 2020
@smitpatel smitpatel deleted the NoTwoApplesAreTheSame0323 branch April 3, 2020 08:55
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.

3 participants