Unit and Component testing | David Tzemach
Updated: Jan 26, 2022
Unit tests are the first level of software testing, where individual software units are tested. It is considered “white box” testing. The primary purpose is to validate that each software unit performs as designed.
A unit is defined as the smallest testable part of the software. Usually, a function/procedure with one or more inputs generates a single output that developers may use to uncover any syntax, technical or logical problems in the code.
benefits of unit testing
Performed by developers - Developers perform the tests; they have a different state of mind than testers use during the regular testing cycles, which increases the variety of the tests).
Automated tests – Unit tests are all automated. Therefore, developers/automated frameworks can execute the tests daily to guarantee that the new code does not affect the existing code-base.
Simplifies the debugging process - When performing unit tests, the developer examines the functionality of the smallest testable part of the code; therefore, it is easy to debug each failure.
Increases the confidence in the written code - Unit tests are an excellent tool for developers to gain confidence in their code. Each code change can be examined quickly and after the engineer already knows the previous testing outcomes. In addition, writing tests and executing them forces the developers to understand the logical structure of the code better.
Bugs are found earlier - When using unit tests, the team minimizes the number of bugs that must be caught at later stages of the development process. Like the traditional development process, finding bugs as early as possible is helpful.
Limitations of Unit testing
Limited test coverage - Unit tests can cover only the functional aspects of the tested code; they cannot indicate other elements such as user interface, usability etc.
The limitation of running complex scenarios - Unit tests test small parts of the code based on simple input and output. It cannot be used to test complex scenarios tested in other test layers.
Test maintenance - When working with methods that frequently change (e.g. complex algorithms), the maintenance of the tests may require a significant investment of both time and money.
Component testing overview
Component testing is defined as a testing type in which testing is performed on a specific (isolated) component. In this type of testing, the team uses real testing data (instead of fabricated data generated to execute unit tests) to test the significant functions of the component.
To explain this type of testing, let’s imagine that we want to test a web application and that the component that we will test is the log-in page, which is separated from the other components.
We will test the page’s performance.
We will test both negative and positive inputs.
We will test all significant functions.
We will test the user interface for usability.
We will test the user interface for accessibility.