The concepts of unit test
and integration test
are well-defined: the former tests one component, the latter tests more than one component.
I use Effort
to test my Entity Framework
repositories. Effort is an in-memory database implementation, so we don't hit an actual database but just the memory so it's faster.
I'm testing solely my repositories by creating some fake data and populating an in-memory database with this fake data. I'm not mocking the data context. Should these be considered unit tests or integration tests?
Edit: I'm testing the methods of my repositories - e.g. CustomerRepository.GetAllCustomers. I'm populating this in-memory database with (say) 5 customers, calling the method, and asserting that I get those 5 customers back.
EF Core In-Memory Database Provider This database provider allows Entity Framework Core to be used with an in-memory database. While some users use the in-memory database for testing, this is generally discouraged; the SQLite provider in in-memory mode is a more appropriate test replacement for relational databases.
Both the Unit Test and Integration Test are very important and useful. Neither of these two tests can be considered more important than the other. They should be performed rigorously, on time and should always be an integral part of the development process.
Integration tests focus on testing how separate parts of the program work together. In the context of applications using a database, integration tests usually require a database to be available and contain data that is convenient to the scenarios intended to be tested.
From your description of test for method CustomerRepository.GetAllCustomers
, it does look to be a unit test since you are not using other services ( external or within your app ).
If your method is simply using a db Connection
object to retrieve rows from in - memory db instead of real db and no other public services being called or being mocked ( if called ) then you are doing a unit test ( which does seem the case to me even though you have not shared code of CustomerRepository.GetAllCustomers
) .
As already pointed out by a previous answer, just using in-memory db is not enough to tell if your tests are unit or integration esp. if you are testing DAO layer
itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With