Unit Testing in Software Engineering
- In software engineering, unit testing is a level of software testing in which individual units/components are tested.
- A unit is a smallest testable part/module of any software application. In procedural programming, a unit is an individual program, function, procedure. In object-oriented programming, a unit may be a method.
- Unit testing of the software product is done during the software development stage saves time and money in the end.
- If unit testing is skipped by the software developers then there is higher chances of defects during the integration, system, acceptance and also beta testing.
- The goal of unit testing is to isolate each part of source code and verifies that each part works properly as designed and to check that source code meets the requirements and gives the expected output.
- The main advantage of unit testing is that it identify the problem earlier in the application and if any issue occurs then it can be fix before integrate the units.
In SDLC, STLC, V Model, unit testing is the first level of software testing done before integration testing.
Unit testing is a white box testing which is performed by the software developers and in rare cases, this testing may be done by independent software testers and quality assurance engineers also do unit testing.
Objective of unit testing :
- Unit testing separate a section of code.
- To verify that source code performs as designed in an expected manner.
- This testing is used to test every function and procedure individually.
- To fix defects early in software development stage.
- Software developers performs this testing to save time and cost both.
- Unit testing helps the developers to understand the code base and enable them to make changes quickly.
- To help for code reuse.
Workflow of Unit Testing:
The workflow of Unit Testing is given below :
- Design Test Cases
- Execute Test Cases
Types of Unit Testing:
There are 2 type of Unit Testing:
A manual approach may employ a step-by-step instructional document. Unit testing is commonly automated but may be performed manual approach. A coder uses a unit-test framework to design automated test cases.
Unit Testing Tools:
- JUnit & EMMA : Java framework
- NUnit : .NET framework
- PHPUnit : PHP framework
- py.test : Python framework
- UnitTest++ & Google C++ : C++ framework
- test-unit : Ruby framework
Advantages of Unit Testing:
- Unit testing allows the programmer to improve the code and make sure that the components works properly in the expected manner.
- Unit testing enables to verify units of an application without waiting for others to be completed due to the modular nature of this testing.
- This testing reduces bugs in the newly developed features or when altering the existing working of an application.
- It helps to maintain the code.
- This testing is used to reducing the cost of defect fixes because defects are found early in the software development stage.
- Fixing defects in unit testing can fix many other defects arising in later development.
- Due to decreased defect count overall development time can be saved to complete a project.
Disadvantages of Unit Testing:
- Unit testing can not be expected to find all defects/errors present in a program/code.
- Unit testing is not able to find integration level errors or system level errors because it only focuses on components of the code/program.
- This testing can be time-consuming.
Following are related articles for reading –