The art of unit testing explained
Swayam Prakasha explores and explains one of the most important methodologies in modern software development…
Software development and testing are considered to be two sides of the same coin. It is not surprising to see that a lot of focus is given to the testing phase and this only ensures better quality, thereby enhancing the customer satisfaction. Software testing plays a significant role in the success of any project. In simple words, software testing can be defined as a process of verifying and validating that a software application or program meets the business and technical requirements that guided its design and development, and works as expected. It is this testing phase that identifies defects, flaws or errors that need to be fixed.
Software testing has three main purposes:
- Defect finding
The verification process confirms that the software meets its technical specifications. A specification is a description of a function in terms of a measurable output value given a specific input value under
The validation process confirms that the software meets the business requirements. A defect is a variance between the expected and actual result. The defect’s ultimate source may be traced to a fault introduced in the specification, design, or development (coding) phases.
Software testing answers questions that development testing and code reviews can’t. Some of the questions answered by software testing are:
- Does it meet the users’ requirements?
- Does it really work as expected?
- How does it scale when more users are added?
- What about its performance?
- How does it work when more users are added?
- Is it ready for release?
When we are able to find answers to the above questions, it saves time and money by identifying defects early. It also reduces development downtime. We will be able to provide better customer service by delivering a better application. And the important thing is that it will help us to identify the areas where our programmers need trainings.
The value of software testing is that it goes far beyond testing the underlying code. It also examines the functional behaviour of the application. Behaviour is a function of the code, but it doesn’t always follow that if the behaviour is bad then the code is bad. It’s entirely possible that the code is solid, but the requirements were inaccurately or incompletely collected and communicated. It’s entirely possible that the application can be doing exactly what we’re telling it to do, but we’re not telling it to do the right thing. It is important to understand that the testing provides an opportunity to validate and verify things like the assumptions that went into the requirements, the appropriateness of the systems that the application is to run on etc.
The V-model has gained acceptance because of its simplicity and straightforwardness. If you look at the pictorial representation of V-model, the first test level is unit testing. It is also known as component testing. Unit testing can be considered as a method by which individual units are tested to see whether they are functioning as expected. Unit testing is typically done by software developers, as they are the only ones who understand how a specific unit or module works.
The problem with testing a unit is that it performs only a small part of the functionality of a system, and it relies on co-operating with other parts of the system which may not have been built yet. To overcome this, the developer either builds or uses special software to trick the component into believing it is working in a fully functional system.
The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. Unit testing allows the programmer to refactor code at a later date. This will help in making sure the module still works correctly. It also simplifies integration testing – unit testing helps to eliminate uncertainty in the units themselves. By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier.
In unit testing, a series of standalone tests are conducted. Each test examines an individual module that is new or has been modified. Each test validates a single module that, based on the technical design documents, was built to perform a certain task with the expectation that it will behave in a specific way or produce specific results.
Generally, unit tests focus on functionality and reliability, and the entry and exit criteria can be the same for each module or specific to a particular module. Unit testing is done in a test environment prior to system integration. If a defect is discovered during a unit test, the severity of the defect will determine whether or not it will be fixed before the module is approved. In summary, unit tests help developers to reduce the number of bugs, hours spent on debugging, and thereby contributing to more stable software.