-
Notifications
You must be signed in to change notification settings - Fork 56
Home
The NuGet package EfCore.TestSupport is a netstandard2.0 library containing methods to help you unit test applications that use Entity Framework Core for database access.
This wiki defines the various groups and the signatures of the methods. The various groups of methods are listed below (see sidebar for links):
- Helpers to create an in-memory Sqlite database for unit testing
- Helpers to create an InMemory database for unit testing
- Helpers to create connection strings with a unique database name (via appsetting.json)
- Helpers for creating unique SQL Server databases for unit testing
- Helpers for creating an empty database, and deleting SQL unit test databases
- Various tools for getting test data, or file paths to test data
- A tool for applying a SQL script file to a EF Core database
- Tools for capturing EF Core logging.
- EfSchemaCompare: Tool to compare EF Core's view of the database with an actual database.
- Seed from Production feature: a way to produce more representative unit test data.
- xUnit Fluent Validations.
This GitHub repository contains the source of the The NuGet package
EfCore.TestSupport
is the project TestSupport
and various unit tests that check the project TestSupport
.
In NET Core the EfCore.TestSupport features work when running the unit tests via Visual Studio Test Explorer, or any other test runner such as Resharper.
In NET Framework, by default, EfCore.TestSupport methods that accessing files or appsettings fails when running via Visual Studio Test Explorer (but resharper works). This is because the NET Framework XUnit runner defaults to using a shadow copy. The solution is to add a XUnit configuration file to turn off the shadow copy. I have added a project called Net472Test
to test this and you can find my XUnit xunit.runner.json file here that provides the correct setup. NOTE: read the XUnit config docs as you need to set the file properties for it to work.
- Testing against a PostgreSQL db
- Changes in EfCore.TestSupport 5
- Testing with production data
- Using an in-memory database (old)