11

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.

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Sabir, you are right. I am not using any other service (I'm mocking all the dependencies) and I am using an in-memory database. Since I asked this question, I learned that one of the requirements of unit tests is that they are performed in memory instead of hitting an actual database. Thank you!
0

Using an in-memory database is not enough information to tell whether you are writing a unit test or integration test.

If you are only testing a small component like a method of a class then yes it's a unit test. But if that method calls other public methods to do it's job and you don't mock those dependencies, then that would be an integration test.

2 Comments

Thank you for your that note. I added more details about what I'm doing. Thanks!
Can you add sample code or pseudocode for GetAllCustomers to get an idea how you are handling dependencies? E.g. customer factory, db connection etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.