Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing with an in-memory database. Unit test or integration test?

Tags:

unit-testing

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.

like image 613
user11081980 Avatar asked Jun 24 '16 18:06

user11081980


People also ask

Should you use in memory database for testing?

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.

Should I unit test or integration test?

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.

What is integration test in database?

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.


1 Answers

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 Connectionobject 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.

like image 122
Sabir Khan Avatar answered Oct 20 '22 19:10

Sabir Khan