Tabnine Office Hours every Wednesday: See our new Code Review Agent in action
Home / Blog /
Unit testing vs. integration testing
//

Unit testing vs. integration testing

//
Tabnine Team /
4 minutes /
December 1, 2020

It’s hard to understate the importance of testing in software development. In fact, testing products before release is critical no matter what type of product you’re developing. No one wants a defective product, no matter how feature-rich or innovative. And no one wants to be woken in the middle of the night to fix a line of code that just cost the organization thousands.

So it’s no wonder that there are countless methodologies and approaches to testing and quality assurance of products and services. When it comes to software testing, having a well-planned and thorough testing strategy throughout the software development cycle is important

Why software testing matters

Though many prefer the “code fast, break things” approach, having a testing strategy and process are something you should develop and adopt long before your software meets the clumsy hands of end-users. This is especially true when the development of a single piece of software is divided among numerous developers or teams of developers.

Making sure it all works in tandem without any components breaking the functionality of others apart is no easy task. It requires different kinds of tests, performed by different stake-holders in the process at different stages of development.

Two of the most commonly used types of tests used in software development today are unit tests and integration tests.

In this post, we’ll define what each is, who is responsible for it, how it is performed and when. In addition, we’ll compare the two side-by-side and discuss the importance of using both.

What is unit testing?

Unit testing is a type of software testing that is applied to individual units of code, also known as modules or components. Unit tests are usually written and conducted by developers to ensure the code functions as expected and is ready to be included in the project codebase. They are the first tests to be run on any code throughout the development lifecycle.

Fairly basic and narrow, unit tests do not take into account any dependencies like database, network or other software components. Since unit testing only checks for basic functionality, then nonfunctional and coverage issues, bugs are never logged. Instead, they are fixed by the developer before ever getting near the codebase.

Why do you need to perform unit testing

Testing each function, procedure, component and method individually may sound like a hassle. However, it helps to reduce the costs of bug fixes later on. Not only does it help prevent bugs in the software codebase, but it also promotes good coding hygiene. By running unit tests, developers can learn from their mistakes almost immediately.

Moreover, since it is the very first level of testing? Having good unit tests leads to a significant reduction in time and effort needed from developers and testers to find and fix bugs down the road to production. The sooner you catch bugs – the better. And this is the earliest test that can.

What is integration testing?

Integration testing is a type of software testing that is intended to check and verify that different modules and components of the software work together as expected when combined. Integration tests are traditionally performed by testers using test stubs and test drivers.

Complex and fairly difficult to set up (in most cases), integration tests aim to locate and expose errors and issues in the interaction and integration of code modules. These modules, that were individually tested through unit tests previously, are then checked for faults in integration between them.

In integration testing, the code is tested using real dependencies like hardware, network, database and others. Issues encountered are then logged as bugs.

Why you need to perform integration testing

Being as complex and tricky as it is to test compatibility between multiple components, it’s almost unavoidable. The product you deliver is not just a collection of functions and variable names that compile. You’re creating a system or application that needs to work in a holistic way, without any hidden hindrances.

A single function or component may work just fine as a unit in testing. However, running integration tests can help you uncover numerous bugs that result from incompatibility between components that work just fine on their own. Such issues include data exchange bottlenecks, erroneous function calling and unexpected hardware issues on user devices.

Unit testing vs integration testing: side by side comparison

To better understand the similarities and differences, let’s look at unit testing and integration testing side by side.

Unit testingIntegration testing
FunctionalityTesting a single component (unit) for bugsTesting interoperability between multiple components (units)
TargetModulesInterfaces
Owner / conductorDeveloper writing the codeTester
SpeedQuickSlow
ComplexityLowHigh
Scope & dependenciesNarrow scope, ignoring external dependenciesBroad scope, considering all relevant external dependencies
MaintenanceLowHigh
Stage in development lifecycleEarly – as soon as a piece of code is completedPerformed after individual units are tested, and before testing the system in full (system testing)
Code proficiency requiredHighMedium
CostLowHigh
TypesSingle typeDivided into different types: Top-down Integration, Bottom-Up Integration, etc.

Why you need to perform both unit testing and integration testing

Consider a puzzle. No matter how perfectly polished and accurately cut each piece is, if they don’t fit together as expected and intended, they are worthless. On the other hand, poorly printed or cut (or missing) pieces will leave you with an incomplete creation as well.

When it comes to software development operations? Understanding and employing the various tests in the development lifecycle is key to an efficient and headache-free DevOps experience.

So as you orchestrate the phases of testing and quality assurance through your CI/CD pipelines, remember that at the end of the day, you’re the one putting the puzzle together for deployment to end users.