DEV Community

loading...
Cover image for Difference between Unit Testing and Integration Testing?

Difference between Unit Testing and Integration Testing?

Pankaj Kumar
I am javascript developer having experience of 8 years+ on different frameworks/libraries of Javascaipt. I am interested to explore more in js.
・2 min read

Normally a software application is developed by a team of many people. So while developing an application is divided into different modules and modules are divided to different developers of team. When a single developer write some code, let’s say a common function, and test that function then this type of testing is called Unit Testing. When all the different modules are developed and integrated then testing is required to check if the complete application is working properly or not after integrating different modules, This type of testing is called Integration Testing.

Difference between Unit Testing and Integration Testing:

Unit Testing

  1. Unit testing is a type of testing to check if the small piece of code or a single function is doing as per the expectation.
  2. It checks a single component/function of the application.
  3. Its scope is very limited.
  4. It should have no dependencies on code outside its definition.
  5. This is the first type of testing is to be carried out in the Software testing life cycle and generally executed by the developer.
  6. The goal of Unit testing is to test each unit separately and ensure that each unit is working as expected.
  7. Unit testing comes under the White box testing type.

Integration Testing

  1. Integration testing is a type of testing to check if different modules are working as expected after integrating each other.
  2. It checks the overall flow of the application. after the integration of different modules.
  3. Its scope is very wide
  4. This type of testing can have each every element in the software application
  5. This is performed after unit testing. Generally, the script is preferred to test the integration testing
  6. Integration testing is further divided into different types as follows: Top-down Integration, Bottom-Up Integration, etc
  7. Integration testing is coming under both Black box and White box type of testing.

Conclusion

Unit Testing and Integration Testing both are equally important for testing an application. And it's very important to create an application bug-free and work as expected.

Find below the link of the sample application for Integration Testing of Nodejs API: https://jsonworld.com/demo/testing-nodejs-api-with-mocha-and-chai

Discussion (2)

Collapse
layzee profile image
Lars Gyrup Brink Nielsen

It would be useful if you walked us through simple examples of unit and integration tests to show the difference in code.

It would be interesting if you explained a bit about top-down and bottom-up integration testing.

Collapse
arjunrajkumar profile image
Arjun Rajkumar

Nice one, Pankaj! I wrote about a similar topic today :) dev.to/arjunrajkumar/integration-u... But wrote about outside-in approach - starting with integration tests, and then moving down to unit tests.