Unit Testing Guide| Software Testing Material
Unit testing is the first level of testing in software testing where individual components of a software are tested. If you are new to software testing, be sure to read this Beginners’ Guide for Software Testing. Also don’t miss our detailed list of 100+ types of software testing.
Let’s explore what Unit Testing is in detail.
In this article, we are going to see the following:
- What is Unit Testing
- Levels of Software Testing
- Difference between Unit Testing & Integration Testing
- Goals of Unit Testing
- Advantages of Unit Testing
- Unit Testing Method
- Types of Unit Testing
- When Unit Testing is performed
- Who performs Unit Testing
- Tasks of Unit Testing
- Unit Testing Tools
Â
What is Unit Testing:
Â
Unit Testing is also called Module Testing or Component Testing. It is done during the development of an application to check whether the individual unit or module of the application is working properly. It is done by the developers in the developer’s environment.
Â
Levels of Software Testing:
There are four levels of software testing. Each level of software testing verifies the software functionality for correctness, quality, & performance. The four levels of software testing are as follows:
- Unit Testing
- Integration Testing
- System Testing
- Acceptance Testing
Â
Difference between Unit Testing & Integration Testing:
UNIT TESTING | INTEGRATION TESTING |
---|---|
Unit testing is the first level of testing in the Software Testing | Integration Testing is the second level of testing in Software Testing |
Considers each component, as a single system | Integrated components are seen as a single system |
Purpose is to test working of individual unit | Purpose is to test the integration of multiple unit modules |
It evaluates the each component or unit of the software product | It examines the proper working, interface and reliability, after the integration of the modules, and along with the external interfaces and system |
Scope of Unit testing is limited to a particular unit under test | Scope of Unit testing is wider in comparison to Unit testing. It covers two or more modules |
It has no further types | It is divided into following approaches • Bottom up integration approach • Top down integration approach • Big Bang approach • Hybrid approach |
It is also known as Component Testing | It is also known as I&T or String Testing |
It is performed at the code level | It is performed at the communication level |
It is carried out with the help of reusable test cases | It is carried out with the help of stubs and drivers |
It comes under White Box Testing | It comes under both Black Box and White Box Testing |
It is performed by developers | It is performed by either testers or developers |
Â
Goals of Unit Testing:
The goal of Unit Testing are
- To isolate every section of code.
- To make sure individual parts are correct.
- To find bugs early in development cycle.
- To save testing cost.
- To allow developers to refactor or upgrade code at the later date.
Â
Advantages of Unit Testing:
- It finds problems early in the development cycle. So it reduces the cost of testing. The cost of finding a bug earlier is considerably lower than the cost of finding it later.
- It reduces defects when changing the existing functionality (Regression Testing)
- It simplifies the debugging process. Debugging is the process of finding and resolving defects within a program that prevent correct operation of a software. When unit testing is implemented only the latest changes made in the code need to be debugged when a test fails.
- it provides code documentation due to better coding standards and practices
Â
Unit Testing Method:
It is performed by using White Box Testing method.
Â
Types of Unit Testing:
There are two types of Unit Testing – Manual & Automated.Â
Â
When Unit Testing is performed:
Unit Testing is the first level of Software Testing. It is performed prior to Integration Testing.
Â
Who performs Unit Testing:
It is normally performed by Software Developers or White box testers.
Â
What are the tasks of Unit Testing:
Unit Test Plan:
- Prepare
- Review
- Rework
- Baseline
Unit Test Cases/Scripts:
- Prepare
- Review
- Rework
- Baseline
Unit Test:
- Perform
Â
Unit Testing Tools:
There are several automated tools available to assist with unit testing. We will provide a few examples below:
Junit:
JUnit 5Â is the next generation of JUnit. The goal is to create an up-to-date foundation for developer-side testing on the JVM. This includes focusing on Java 8 and above, as well as enabling many different styles of testing.
NUnit:
NUnit is a unit-testing framework for all .Net languages. Initially ported from JUnit, the current production release, version 3, has been completely rewritten with many new features and support for a wide range of .NET platforms.
JMockit:Â
JMockit is open source Unit testing tool. JMockit is a Java toolkit for developer testing, including mocking APIs and a code coverage tool.
EMMA:
EMMA is an open-source toolkit for measuring and reporting Java code coverage. EMMA distinguishes itself from other tools by going after a unique feature combination: support for large-scale enterprise software development while keeping individual developer’s work fast and iterative. Every developer on your team can now get code coverage for free and they can get it fast!
PHPUnit:
PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks.
Here I have hand-picked a few posts which will help you to learn more interview related stuff:
- Integration Testing
- Selenium Tutorial
- Manual Testing Tutorial
- SQL Tutorial for Software Testers
- Performance Testing Tutorial
- Security Testing Tutorial
- API Testing Tutorial