-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
6bc4d21
to
95e82df
Compare
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. | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Co-Authored-By: Andriy Svyryd <AndriySvyryd@users.noreply.github.com>
Co-Authored-By: Andriy Svyryd <AndriySvyryd@users.noreply.github.com>
Part of #1304 and #430