Creating Seed Data for E2E tests with EF Core

454 Views Asked by At

I've done some research into seeding data for my End to End tests that are dependent on things such as an Admin user to login.

Our API is in EF Core, and I'm having trouble figuring out how to seed data. With EF 6, you can use a Seed method in the config.cs file, which runs after migrations are run, but EF Core does not support this method.

What alternative's are there for EF Core & is there any good documentation or tutorials online I can read? I've done some investigating myself, and many of the tutorials have very complicated ways of creating the seed data, and I'm wondering if there is a more standard way to do this.

1

There are 1 best solutions below

0
On

Use InMemory database provider for testing purpose. MS Docs

For seeding use method with TestInitializeAttribute or AssemblyInitializeAttribute (if you're using mstest) where you seed your DB with data.

Article about testing with InMemory provider