A unit test is the smallest testable part of an application like functions, classes, procedures, interfaces. Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
- Unit tests are basically written and executed by software developers to make sure that code meets its design and requirements and behaves as expected.
- The goal of unit testing is to segregate each part of the program and test that the individual parts are working correctly.
- This means that for any function or procedure when a set of inputs are given then it should return the proper values. It should handle the failures gracefully during the course of execution when any invalid input is given.
- A unit test provides a written contract that the piece of code must assure. Hence it has several benefits.
- Unit testing is basically done before integration as shown in the image below.
Method Used for unit testing: White Box Testing method is used for executing the unit test.
When Unit testing should be done?
Unit testing should be done before Integration testing.
By whom unit testing should be done?
Unit testing should be done by the developers.
Advantages of Unit testing:
1. Issues are found at early stage. Since unit testing are carried out by developers where they test their individual code before the integration. Hence the issues can be found very early and can be resolved then and there without impacting the other piece of codes.
2. Unit testing helps in maintaining and changing the code. This is possible by making the codes less interdependent so that unit testing can be executed. Hence chances of impact of changes to any other code gets reduced.
3. Since the bugs are found early in unit testing hence it also helps in reducing the cost of bug fixes. Just imagine the cost of bug found during the later stages of development like during system testing or during acceptance testing.
4. Unit testing helps in simplifying the debugging process. If suppose a test fails then only latest changes made in code needs to be debugged.
Other popular articles:
- What are Software Testing Levels?
- What is Integration testing? Examples, How To Do, Types/Approaches, Differences
- What is Big Bang integration testing?
- What is Efficiency testing in software?
- What is Testing and Configuration Management in Agile development?
Pratima says
is it correct that unit testing can be done by tester checking the functionality of each and every module independently ?
Victor García says
No, when you refer as a tester test the functionality you are talking about Black Box testing (Functionalities). jUint is described as White Box testing (Structure). This is why Developer use to perform jUnit test.
roma says
under Unit testing section, the first sentence reads:
A unit test is the smallest testable part of an application like functions, classes, procedures, interfaces.
From which it means that ‘Unit Test’ is a part of an application, which is incorrect, in my opinion.
Karan says
please read it carefully you will understand it’s written correctly
pooja rawat says
A Unit is the smallest testable part of a system/application (Individual Program,Function ,procedure or class) and the test which is carried on it is called Unit test.
Jose says
Roma is right, the phrase should be corrected as Pooja suggests.
BANDHARFINDER says
Is it Jingjak?