In this article, we have provided an extensive comparison of Unit, Integration and Functional Testing
For any software application, both Unit testing and Integration testing are very important as each of them employs a unique process to test a software application.
However, either one or even both cannot replace Functional testing at any point. Let’s look at the comparison in detail.
What You Will Learn:
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 thing.
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:
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. The sim card is checked for its activation.
Integration Testing Example – Battery and sim cards 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.
We have seen an example in layman’s terms.
Now, let us now take a technical example of a login 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 navigate to the welcome page or home page after a valid entry and click the Login button.
Now, after unit and integration testing is done, let us see the additional test cases that are considered for functional testing:
- 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.
- Is there a welcome message that is to appear after a successful login?
- Is there an error message that should appear on an invalid login?
- Are there any stored site cookies for the login fields?
- Can a deactivated user log in?
- Is there a “forgot password” link for users who have forgotten their passwords?
There are a number of such cases which come to the mind of a functional tester while performing functional testing. However, the developer cannot take up all cases while building the Unit and Integration test cases.
Thus, there are plenty of scenarios that are yet to be tested even after unit and integration testing.
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 the 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 goal here is to match the requirements and the unit’s expected behavior.
Given below are a few key points about unit testing and its benefits:
- Unit testing is done before Integration testing by software developers using white box testing techniques.
- Unit testing not only checks 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 low.
- 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 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 testing saves time and cost, and is reusable and easy to maintain.
JUnit (Java framework), PHPUnit (PHP framework), NUnit (.Net framework) etc. are popular unit testing tools that are used in different languages.
What is Integration Testing
Integration testing involves testing the integration of different parts of the system together. Two different parts or modules of the system are first integrated and then integration testing is performed.
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 gives 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’s discuss each one of them briefly:
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 the integration of modules or units is tested and not the whole system as it is done in system testing.
The Big Bang integration 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 figures below, Unit 1 to Unit 6 are integrated and tested using the Big bang approach.
b) Top-Down Approach
Integration of 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.
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.
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 Testing | Integration 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 execute | Can run slow |
No external dependency. Any external dependency is mocked or stubbed out. | Requires interaction with external dependencies (e.g. Database, hardware, etc.) |
Simple | Complex |
Conducted by developer | Conducted by tester |
It is a type of white box testing | It is a type of black box testing |
Carried out at the initial phase of testing and then can be performed anytime | Must be carried out after unit testing and before system testing |
Cheap maintenance | Expensive maintenance |
Begins from the module specification | Begins 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 code | The 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
A 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 process, 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 are basically comprised 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.
For 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 testing | Integration testing | Functional testing | |
---|---|---|---|
Definition and purpose | Testing 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. |
Complexity | Not at all complex as it includes the smallest codes. | Slightly more complex than unit tests. | More complex compared to unit and integration tests. |
Testing techniques | White box testing technique. | White box and black box testing technique. Grey box testing | Black box testing technique. |
Major attention | Individual modules or units. | Integration of modules or units. | Entire application functionality. |
Error/Issues covered | Unit 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 escape | No chance of issue escape. | Less chance of issue escape. | More chances of issue escape as the list of tests to run is always infinite. |
Also read => What is Feature Testing?
Conclusion
All 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 has given you a clear idea of Unit, Integration and Functional testing along with their differences, though there is much more to these forms of testing!! Don’t forget to provide your feedback/queries in the comments section below. We would love to hear from you.
The difference is very clear now. Thank you for sharing.
Good one, keep it up!!!
Hi Sushma,
Did you do course in Qspiders,Bangalore?.
These concepts are taught there.
Anyways,Nice explanation.
Do not promote your brand over here . lets maintain some integrity here
What an AH?
Seriously. Please maintain some dignity.
Nice clearly explained.
very nice explanation..
Would be more helpful with code examples.
Great article. Thanks.
Integration Testing can be done by either developers or testers. This type of testing also deals with the code part as well. So, It can also come under the White Box Testing Technique.
Described very well, it seems that words Feature testing and Integration testing are interchangeable since you didn’t mention Feature test on the layer above Unit tests.
Very well described here. Thank you.
thanks!
Is Functional testing equal System testing?
Useful information | Easily Understood
Very useful article.
Well structured and understandable information.
Thank you
Very helpful. Thanks
Very helpful comparison of Unit, Integration, and Functional Testing. Thank you.
Very simple and wonderful, thank you 🙂
according to the description, i think so, only SW for example, functional testing is system testing and so-called qualification test in ASPICE SWE.6
frankly speaking, it’s a very good article, however, one question is still in my heart that could Function cover Integration test and unit test? many colleagues answer yes. the disadvantage is more effort need to be paid one issue to be found. unit test and integration test recommend to perform before function test, the purpose is to find the issue as early as possible, such hierarchy test is more applicable on complex system.
my understanding is correct?
Yes, debuggability to find and fix bugs with unit tests and integration tests in place is more easy, fast, and cheap.
It is like this, you want to build Tajmahal, quality issues have to be found at each unit level, rather than entire Tajmahal to be built.. any quality issues found after full hardware Tajmahal is built is a too costly affair and may lead to no fix at all (of course in software Tajmahal, one can fix with merciless refactoring efforts).
If any functional bug comes, it is the duty of the developer to expose the bug in Integration and Unit Level, so that, at least next time a similar bug if reoccurs, can be bought at the unit level.
Nice
Love it! Fully understood the differnce between Unit -=- Integration -=- Functional -=- Testing
Please keep up the good work bro and thank you very much for your great efforts! 🙂
Cheers
Very well explained in a very easy language which can be understood by non-tech people too
Very nicely explained. really helped me to understand what I want to. Thank you so much.
Hello, you say :
For Integration Testing, the following may be the test cases:
1) The user sees the welcome message after entering valid values and pushing the login button.
2)The user should be navigated to the welcome page or home page after valid entry and clicking the Login button.
Then the same 2 points are verified AGAIN in “Functional Test” phase. What’s the value of doing this 2 times ? Aren’t you also verifying the integration implicitly in “Functional test” ? If you don’t execute a “Function/UseCase” during “Integration Test” how do you know that the sysmtmes are integrated correctly ?
Hello,
Was “stimulator” supposed to be “simulator” when describing Drivers for the Bottom-Up approach?
Which kind of testing checks the connectivity between the unit modules?