❔ Mocking with EntityFrameworkCore
Hm,
I'm creating unit tests for a class that has a
private readonly MyDbContext dbContext;
that causes a few problems.
And you can't really mock that as you would everything else, because you cannot instantiate any DbSet collections as they don't have a non-private constructor.
Anybody who has mocked stuff with DbContexts on them? I'm not sure how to approach this.3 Replies
dont mock it problem solved 🙂
Usually if I need to have a dbcontext for my unit tests, I will use the entity framework core in memory database rather than a mock. You can also use sqlite in memory if your using a relational database setup.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.