Category: 

What is Unit Testing?

Article Details
  • Written By: M.L. Browne
  • Edited By: J.T. Gale
  • Last Modified Date: 25 July 2017
  • Copyright Protected:
    2003-2017
    Conjecture Corporation
  • Print this Article

Unit testing in computing refers to a development process that assesses both the function and performance of the smallest discrete software module that can function on its own, also known as a unit. Since measurement is at the core of all software quality programs, each unit test verifies that a unit adheres to the design intention stated in the development plan. The test also validates that the unit behavior and performance is as expected.

Generally, unit tests are themselves small programs in which a developer specifies the acceptable inputs, behaviors, and outputs for the unit and then logs the results for later review and evaluation. A software developer can perform unit testing on an ad hoc basis, or if the main program is large or complex, he or she can add unit tests for inclusion in a larger test harness that exercises several integrated units at once. Regardless, unit testing is an ongoing effort by the developer to confirm that his or her code performs as expected, and as such, is considered an integral part of the overall development process.

Any software development process normally begins with a design phase in which the entire team spends its time writing down the plans for designing, developing, integrating, system testing, accepting, and maintaining new software. Unit testing is a necessary component of all phases. Developers must have a simple way to check that the code changes made in modules yield the anticipated results before integrating those changes into the main program.

Ad

Unit tests are usually written by the same developer whose code will be used. The reason for this is that the unit's programmer has in-depth understanding of the module's design and expected performance. Typically, the developer's test case sets the parameters for all the unit inputs, processing methods, and outputs, and defines the acceptable performance criteria for later integration and acceptance testing.

One key benefit of unit testing is that it encourages the discovery of problems early in the development process. When coding problems are discovered early, corrective actions and fixes usually can take place before buggy code has any negative effect on the integrated application and its users. Even though unit tests cannot catch every possible program error, they significantly reduce errors in later stages of the development process, saving time, money, and resources that would be required for debugging a program through additional validation and verification cycles before release.

Ad

Recommended

Discuss this Article

bythewell
Post 2

@umbra21 - It gets even more complicated when you're working as a programmer. They rarely finish off a program by themselves, often there are quite a few people working on different parts of it.

I think unit testing can work as a way of making sure that everyone is pulling their weight as well. After all, when you have twenty cooks about the soup, you have to be very careful no one inadvertently adds sugar instead of salt.

If there is automated unit testing all along the way, there is no chance of that sort of thing happening.

This helps protect the programmers as well, because if something does go wrong, they can point out that they designed what they were told to design and it worked well enough when it left their hands, so to speak.

umbra21
Post 1

I take all my knowledge of programming from high school classes, but I can understand that unit testing would be absolutely crucial in a large project. Even a smaller one, like we did in class, might need it.

If you imagine all those thousands and thousands of lines of code, and then think about having to dig through all of them to find a problem, you can see what I mean. It can quickly turn into a logistical nightmare, even if the code is well arranged and easy to navigate.

Our teacher was careful to teach us not only the code itself, but how to be tidy with it, so that another person could tell exactly what we did and why we did it there.

Making sure each piece works before assembling them is just common sense, really.

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email