Unit testing: does it save or waste your time?

572-time2.jpg

 

The unit test method has already become a standard for a project of high quality. However, the importance of unit testing is still often underestimated. Being eager to speed-up a project and reduce money and time for software development, customers often try to get rid of unit testing in the project as they do not understand its benefits.  

Developers will agree that it is usually a problem to convince management of the project or the customer that unit testing is also an essential part of the software development. Of course you may think that it is enough to rely on the manual testing of a QA department or convince yourself that the skills of developers are strong enough not to warrant the unit tests, which may seem like an outdated activity.

WHAT ARE UNIT TESTS?

Unit tests help determine if the isolated modules of software work correctly. After separate functionalities or modules are verified, parts of the software can be merged together and tested as a whole (Integration Testing and System Testing).

Unit testing (usually automated) makes a basis for a popular software development approach known as Test Driven Development (TDD) that implies first writing tests, then on the basis of these tests creating a code to pass the tests, and then refactoring the code to acceptable standards. Not every team uses TDD in its classic way. Each team or individual developers adapt different technics to the realities of their projects.

Web Development Services and Solutions Require Trusted Expertise Discover how Svitla Systems empowers your web development initiatives with innovative technologies and proven experience. Learn More

WHY YOU MAY WANT TO DO UNIT TESTING?

There are several reasons why doing unit tests is recommended:

1. Bugs preventing. Unit testing helps developers make refactoring and regression easier (?)  when new functionalities are added in the future. You can just write a test once you find a bug and prevent that bug from re-appearing in the future.

2. Documentation. Unit tests can be used as the documentation for code, which is extremely important for big projects. If a new developer starts working on the product, unit tests written by his/her predecessor will be very helpful for the developer to get through and understand the existing code.

3. Clarification of specs. Unit tests let you foresee in advance the testability of the functionality, find some gaps in the specification, and ask a Product Owner questions before the development starts.

4. Time saving. Unit testing helps a QA team (or developers) to start testing separate functionalities (modules) without waiting when all of them are developed and integrated.

5. Money saving. The earlier you start testing, the more money you save. Mistakes not discovered early become more expensive as the project comes closer to the release.

TO WRITE OR NOT TO WRITE THE UNIT TESTS?

During the past decade, teams have been using unit testing in various projects in different ways. Time dedicated to writing unit tests prevents and eliminates many troubles. And from my own experience and experience of my colleagues, we can say that each hour spent on unit testing saves ten hours of troubleshooting later in a project. Usually critical errors occur in a project at the worst possible moment, when you are not expecting them at all. It is good if the problem is identified at the beginning of a project when it is easy to fix it. The defects found in the late stages of a project are expensive and put a project at risk of delay.

Having unit tests will not solve all your problems but at least it will save the project from serious rollbacks because of the undiscovered defects.

SVITLA SYSTEMS EXPERIENCE

At Svitla, we use Unit Testing in many projects: Ingenico, Ancestry, Ooma, to name a few. Test coverage in server-side API allows systematizing all functions and fine-tuning work of many components. Tests on mobile (Android) part of the project allow to identify all errors in reporting API, ensuring smooth operation of the respective functionality. Using unit tests on the server and on the client side provide a great set of regression in testing and help to identify and localize errors much faster, while supporting the project in a consistent state. 

FAQ

What is meant by unit testing?

Unit testing is a process of testing small, individual pieces of code, usually functions or modules, in isolation from the rest of the application to check if they work correctly. It is mostly automated and becomes the main element for methodologies like Test-Driven Development because it requires writing tests before actual implementation coding. Unit tests will prevent major late discoveries by documenting code as it changes and defining requirements, but they do add time upfront. It does save much time for future problem analysis and keeps the system stable while evolving.

Why are they called unit tests?

They are called unit tests because they focus on testing the smallest units of code, in isolation, within a software application. Units may be individual functions, methods, or procedures performing a particular task. The purpose is to make sure that these independent elements work properly when integrated with other parts of the system. Granular testing helps in detecting defects at an early stage and also builds confidence in the reliability of each and every building block of the software.

Who usually does unit testing?

Unit testing essentially falls under the developers. Since they are the ones who write the code, they should be the ones to create tests that would verify whether individual units are working properly or not. It easily merges into the development workflow and, in some cases, methodologies such as <TDD>, wherein even tests are written before coding begins. The QA team performs broader testing; however, unit testing falls under this because it is the specific code unit and its quality that must be ensured.

What is unit testing vs QA testing?

Unit testing is a practice by which developers automatically test small, isolated pieces of code so that every function or module runs properly on its own, often not fully dependent on features being integrated. On the other hand, QA testing covers bigger parts of a system or even the entire product to make sure integrated features work together as they should and meet business requirements. If unit testing is designed to kill the bugs early, support refactoring, and serve as living documentation, QA testing validates the end-to-end behavior, user flows, and general quality of the product before release. The two are also complementary; strong unit tests lessen defects and make QA testing more efficient.

What are the types of unit testing?

Common types of unit testing are based less on formal categories and more on how and where it is applied. Individual function, class, or module tests on the server side (typically APIs) to verify business logic and data handling, and on the client side (mobile or web code) to validate UI related logic and interactions are automated unit tests that developers write. These tests can be used during development – as well as later to prove that nothing has broken when refactoring code or adding new features – as regression tests. Used together, they form a net of safety enabling fast, reliable change in many different parts of a system.