Understanding The Difference Between Unit, Integration and Functional Testing

For any software application, both Unit testing and Integration testing are very important as they each employ unique processes to test the software application. But one or both of them cannot replace Functional testing.

In this article, we will understand Unit, Integration, and Functional testing and clarify the differences between these forms/levels of testing.

unit-integration-and-functional-testing-difference

For absolute newcomers, let us understand these three types of testing with an oversimplified example: For a functional mobile phone, the main parts required are “battery” and “sim card”.

  • Unit testing– the battery is checked for its life, capacity and other parameters. Sim card is checked for its activation.
  • Integration Testing battery and sim card are integrated i.e. assembled in order to start the mobile phone.
  • Functional Testing– the functionality of the mobile phone is checked in terms of its features and also battery usage as well as sim card facilities.

functional-testing_-battery-chargepng

Now that we have seen the example in layman’s terms, let us now take a technical example, the login page:

functional-testing_log-in-page

Almost every web application requires its users/customers to log in. For that, every web application has to have a “Login” page that 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
  • Login button is enabled only after valid values(Format and length wise) are entered in both fields

For integration testing, the following may be the test cases:

  • User sees the welcome message after entering valid values and pushing the login button
  • User should be navigated to the welcome page or home page after valid entry and clicking 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 login on clicking the login button after entering 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 invalid login?
  4. Is 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 plenty of scenarios 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.

Unit Testing:

As the name suggests, this level involves testing of a ‘Unit’. Here unit can be the smallest part of the application that is testable; be it a 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 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 issues at a later stage too because 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 used for different languages.

------------

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 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 modules gives 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 in time.

Please do not confuse this approach of integration testing with system testing; only integration of modules or units is tested and not the whole system as 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 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.

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

Functional testing:

A black box testing technique, where the functionality of the application is tested to generate desired output on providing 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 Business scenario based functional testing, testing is performed 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.

How are Unit, Integration, and Functional testing different?

Now that we have a brief idea of Unit, Integration, and Functional testing, 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 together for performing tasks.Testing the behaviour of the application as per the requirement.
ComplexityNot at all complex as it includes 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:

The unit, Integration, and Functional testing: All three of them 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 has given you a clear idea about Unit, Integration and functional testing and their differences, although there is much more to these forms of testing.

About the author: This is a guest post by Sushma S. She is having 4+ years of software testing experience and currently working as a Senior  Software Test Engineer

Feel free to write your comments and/or thought below :)




5 comments ↓

#1 Devasis

The difference is very clear now. Thank you for sharing.

#2 Suchintya

Good one, keep it up!!!

#3 nag

nice.

#4 RK

Hi Sushma,
Did you do course in Qspiders,Bangalore?.
These concepts are taught there.
Anyways,Nice explanation.

#5 vino

Nice clearly explained.

Leave a Comment