Many people so I read in google strive for unit-testing the repository classes with a so called in-memory database compared to integration tests with a real database.
Where is the problem of doing the latter?
Many people so I read in google strive for unit-testing the repository classes with a so called in-memory database compared to integration tests with a real database.
Where is the problem of doing the latter?
If you are using EF, you don't have to write tests to see whether EF persist data correctly or not. So you don't need a real database for the testing, all you need to test is your code logic and in-memory database is best suitable in this case, it helps to separate of concerns, flexible, easy to run and run faster than using a real database.
Furthermore, running integration tests with a real database is quite complex. It requires some configuration(connection string, drop and re-create database...) before running which may take time. The tests may fail because of mis-configuration(e.g. using shared database during testing) and it takes time to debug.
Whether you are testing against an in memory database or real database you are not doing unit tests - both are integration tests. Both will actually test some form of connection and provider implementation.
The main benefits I would see of using an in memory database vs a real database are
Depending on your pattern (i.e. if you're using a unit of work), it is likely that you don't even need a database to test your repositories.