Can a unit test also serve as an integration test?


I provided the following post in which I asked how to write a test once and specify it as a unit test or an integration test. Apparently, people did not like my question based on their teachings of what a unit test is versus an integration test. They have been trained to believe that the code used to write a unit test must be separated from the code used to write an integration test.

Question 1:

If you are unit testing a view-model and you inject a mock as a dependency instead of an object that actually relies on an external system, is it still a unit test?

I would say yes.

Question 2:

If you take that same test and you swap out the mock dependency with a real external system dependency (i.e. SQL Server), is it still a unit test?

I would say no. I would say that what was once a unit test is now a light-weight integration test because it now relies on an external system. The same code is still being exercised. However, we are now relying on an external system to satisfy an objective.


In conclusion, I believe that the code that serves as a unit test can also execute as a light-weight integration test by simply swapping out dependencies that the system-under-test relies on.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: