The Differences Between Unit Testing, Integration Testing and Functional Testing

A Detailed Comparison of Unit, Integration and Functional Testing:

For any software application, both Unit testing, as well as Integration testing, is very important as each of them employs a unique process to test a software application.

But any one or even both cannot replace Functional testing at any point.

Unit, Integration and Functional Testing

Unit Testing Vs Integration Testing Vs Functional Testing

Unit testing means testing individual modules of an application in isolation (without any interaction with dependencies) to confirm that the code is doing things right.

Integration testing means checking if different modules are working fine when combined together as a group.

Functional testing means testing a slice of functionality in the system (may interact with dependencies) to confirm that the code is doing the right things.

Functional tests are related to integration tests, however, they signify to the tests that check the entire application’s functionality with all the code running together, nearly a super integration test.

Unit testing considers checking a single component of the system whereas functionality testing considers checking the working of an application against the intended functionality described in the system requirement specification. On the other hand, integration testing considers checking integrated modules in the system.

And, most importantly, to optimize the return on investment (ROI), your code base should have as many unit tests as possible, fewer integration tests and the least number of functional tests.

This is illustrated best in the following test pyramid:

Image result for unit testing vs functional testing vs integration testing

Unit tests are easier to write and quicker to execute. The time and effort to implement and maintain the tests increases from unit testing to functional testing as shown in the above pyramid.

Example: 

Let us understand these three types of testing with an oversimplified example.

E.g. For a functional mobile phone, the main parts required are “battery” and “sim card”.

Unit testing Example – The battery is checked for its life, capacity and other parameters. Sim card is checked for its activation.

Integration Testing Example – Battery and sim card are integrated i.e. assembled in order to start the mobile phone.

Functional Testing Example – The functionality of a mobile phone is checked in terms of its features and battery usage as well as sim card facilities.

functional-testing_-battery-chargepng

We have seen an example in layman’s terms.

Now, let us now take a technical example of a login page:

functional-testing_log-in-page

Almost every web application requires its users/customers to log in. For that, every application has to have a “Login” page which has these elements:

  • Account/Username
  • Password
  • Login/Sign in Button

For Unit Testing, the following may be the test cases:

  • Field length – username and password fields.
  • Input field values should be valid.
  • The login button is enabled only after valid values (Format and lengthwise) are entered in both the fields.

For Integration Testing, the following may be the test cases:

  • The user sees the welcome message after entering valid values and pushing the login button.
  • The user should be navigated to the welcome page or home page after valid entry and clicking the Login button.

Now, after unit and integration testing are done, let us see the additional test cases that are considered for functional testing:

  1. The expected behavior is checked, i.e. is the user able to log in by clicking the login button after entering a valid username and password values.
  2. Is there a welcome message that is to appear after a successful login?
  3. Is there an error message that should appear on an invalid login?
  4. Are there any stored site cookies for login fields?
  5. Can an inactivated user log in?
  6. Is there any ‘forgot password’ link for the users who have forgotten their passwords?

There are much more such cases which come to the mind of a functional tester while performing functional testing. But a developer cannot take up all cases while building Unit and Integration test cases.

Thus, there are a plenty of scenarios that are yet to be tested even after unit and integration testing.

testing-phases

It is now time to examine Unit, Integration and Functional testing one by one.

What is Unit Testing?

As the name suggests, this level involves testing a ‘Unit’.

Here unit can be the smallest part of an application that is testable, be it the smallest individual function, method, etc. Software developers are the ones who write the unit test cases. The aim here is to match the requirements and the unit’s expected behavior.

Below are a few important points about unit testing and its benefits:

  • Unit testing is done before Integration testing by software developers using white box testing techniques.
  • Unit testing does not only check the positive behavior i.e. the correct output in case of valid input, but also the failures that occur with invalid input.
  • Finding issues/bugs at an early stage is very useful and it reduces the overall project costs. As Unit testing is done before integration of code, issues found at this stage can be resolved very easily and their impact is also very less.
  • A unit test tests small pieces of code or individual functions so the issues/errors found in these test cases are independent and do not impact the other test cases.
  • Another important advantage is that the unit test cases simplify and make testing of code easier. So, it becomes easier to resolve the issues at a later stage too as only the latest change in the code is to be tested.
  • Unit test saves time and cost, and it is reusable and easy to maintain.

JUnit (Java framework), PHPUnit (PHP framework), NUnit (.Net framework) etc. are popular unit testing tools that are used for different languages.

What is Integration Testing?

Integration testing is testing the integration of different part of the system together. Two different parts or modules of the system are first integrated and then integration testing is performed.

integration-testing


The aim of integration testing is to check the functionality, reliability, and performance of the system when integrated.

Integration testing is performed on the modules that are unit tested first and then integration testing defines whether the combination of the modules give the desired output or not.

Integration testing can either be done by independent testers or by developers too.

There are 3 different types of Integration testing approaches. Let us discuss each one of them briefly:

different-types-of-integration-testing

a) Big Bang Integration Approach

In this approach, all the modules or units are integrated and tested as a whole at one time. This is usually done when the entire system is ready for integration testing at a single point of time.

Please do not confuse this approach of integration testing with system testing, only the integration of modules or units is tested and not the whole system as it is done in system testing.

The big bang approach’s major advantage is that everything integrated is tested at one time.

One major disadvantage is that it becomes difficult to identify the failures.

Example: In the figure below, Unit 1 to Unit 6 are integrated and tested using the Big bang approach.

integration-testing_big-bang-approach

b) Top-Down Approach

Integration of the units/modules is tested from the top to bottom levels step by step.

The first unit is tested individually by writing test STUBS. After this, the lower levels are integrated one by one until the last level is put together and tested.

The top-down approach is a very organic way of integrating as it is consistent with how things happen in the real environment.

The only concern with this approach is that the major functionality is tested at the end.

integration-testing_top-down-approach

c) Bottom-Up Approach

Units/modules are tested from bottom to top level, step by step, until all levels of units/modules are integrated and tested as one unit. Stimulator programs called DRIVERS are used in this approach. It is easier to detect issues or errors at the lower levels.

The major disadvantage of this approach is that the higher-level issues can only be identified at the end when all the units have been integrated.

integration-testing_bottom-up

Unit Testing vs Integration Testing

Having had enough discussion about unit testing and integration testing, let us quickly go through the differences between the two in the following table:

Unit TestingIntegration Testing
Tests the single component of the whole system i.e. tests a unit in isolation.Tests the system components working together i.e. test the collaboration of multiple units.
Faster to executeCan run slow
No external dependency. Any external dependency is mocked or stubbed out.Requires interaction with external dependencies (e.g. Database, hardware, etc.)
SimpleComplex
Conducted by developerConducted by tester
It is a type of white box testingIt is a type of black box testing
Carried out at the initial phase of testing and then can be performed anytimeMust be carried out after unit testing and before system testing
Cheap maintenanceExpensive maintenance
Begins from the module specificationBegins from the interface specification
Unit testing has a narrow scope as it just checks if each small piece of code is doing what it is intended to do.It has a wider scope as it covers the whole application
The outcome of unit testing is detailed visibility of the codeThe outcome of integration testing is the detailed visibility of the integration structure
Uncover the issues within the functionality of individual modules only. Does not exposes integration errors or system-wide issues.Uncover the bugs arise when different modules interact with each other to form the overall system

Functional Testing

black box testing technique, where the functionality of the application is tested to generate the desired output on providing a certain input is called ‘Functional testing’.

In our software testing processes, we do this by writing test cases as per the requirements and scenarios. For any functionality, the number of test cases written can vary from one to many.

Test cases basically comprise of the following parts:

  • Test Summary
  • Prerequisites (if any)
  • Test case input steps
  • Test data (if any)
  • Expected output
  • Notes (if any)

“Requirement-Based” and “Business scenario-based” are the two forms of functional testing that are carried out.

In Requirement based testing, test cases are created as per the requirement and tested accordingly. In a Business scenario based functional testing, testing is performed by keeping in mind all the scenarios from a business perspective.

However, the major disadvantage of functional testing is the probable redundancy in testing and the possibility of missing some logical errors.

Exact Difference

Let’s look at their differences.

Here are some of the major ones:

 Unit testingIntegration testingFunctional testing
Definition and purposeTesting smallest units or modules individually.Testing integration of two or more units/modules combined for performing tasks.Testing the behavior of the application as per the requirement.
ComplexityNot at all complex as it includes the smallest codes.Slightly more complex than unit tests.More complex compared to unit and integration tests.
Testing techniquesWhite box testing technique.White box and black box testing technique. Grey box testingBlack box testing technique.
Major attentionIndividual modules or units.Integration of modules or units.Entire application functionality.
Error/Issues coveredUnit tests find issues that can occur frequently in modules.Integration tests find issues that can occur while integrating different modules.Functional tests find issues that do not allow an application to perform its functionality. This includes some scenario-based issues too.
Issue escapeNo chance of issue escape.Less chance of issue escape.More chances of issue escape as the list of tests to run is always infinite.

Conclusion

All these three testing types are correlated.

To attain full coverage, it is required to have unit tests for the paths/lines of code, functional and Integration tests for assurance that the ‘units’ work together cohesively.

Hope this article would have given you a clear idea about Unit, Integration and Functional testing along with their differences, though there are much more to these forms of testing!!

Recommended Reading


6 thoughts on “The Differences Between Unit Testing, Integration Testing and Functional Testing”

Leave a Comment