Integration Tests

What is an integration test

Sometimes there is not a clear distinction on what is an integration test and what is a unit test.

Basic rule of thumb is that if

  1. a test uses the database
  2. a test uses the network
  3. a test uses an external system (e.g. a queue or a mail server)
  4. a test reads/writes files or performs other I/O

…then it is an integration test and not a unit test. Below is brief comparison between the two.

Unit test Integration test
Results depends only on Java code Results also depends on external systems
Easy to write and verify Setup of integration test might be complicated
A single class/unit is tested in isolation One or more components are tested
All dependencies are mocked if needed No mocking is used (or only unrelated components are mocked)
Test verifies only implementation of code Test verifies implementation of individual components and their interconnection behaviour when they are used together
A unit test uses only JUnit/TestNG and a mocking framework An integration test can use real containers and real DBs as well as special integration testings frameworks (e.g. Arquillian or DbUnit)
Mostly used by developers Integration tests are also useful to QA, DevOps, Help Desk
A failed unit test is always a regression (if the business has not changed) A failed integration test can also mean that the code is still correct but the environment has changed
Unit tests in an Enterprise application should last about 5 minutes Integration tests in an Enterprise application can last for hours



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 )

Google+ photo

You are commenting using your Google+ 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