Many developers, as well as testers, have a hard time understanding exactly what it means to “unit test” code that has been written. What is it exactly? Why is it so important? What does it mean for the developers and team?
Let’s start out with what it is…if you look at the literal definition, you will see that it is the testing of each unit of developed code. Just take a look at this article on Wikipedia for clarification. This thing called unit testing is a way of testing almost every line of code that is written. Another way of looking at unit testing is that it is technology-facing and helps to ensure we are building the way we should and nothing more. When we do unit testing, it sorta feels like when we assemble something we bought–we make sure each part is present, working properly, and is accounted for before we start assembling.
Now that you know what it is, why is it so important? Well, think about the meaning first—testing of each unit of developed code. When each unit of code has been tested, it gives more confidence that the code is more defect-free. A lot of the code that is developed is done so with the end result in mind. However, if you only test the end result, you may miss a prime defect that is hidden inside the code.
Knowing what it is and why it’s so important, what does that mean for the team; how does it impact them? The most obvious impact is time. If each unit of code is tested, common sense tells you it will take more time to do so. Now, with that in mind, if we take a bit of time to test virtually every line of code when it is written, what is the probability of missing a defect at that point?—very little! When that happens, when we find a defect when a unit of code is written, we can fix it then instead of waiting to find it after all the code is written and others are involved.
There is another reason to do unit testing earlier. Take into consideration the graph below that shows the exponential increase in cost the later a defect is found. As you see from the graph, if we are doing unit testing, we tend to find defects much earlier, resulting in a more cost effective way to eliminate defects.
Check back for the next installment of “You Call That Unit Testing—What We Really Do” in a couple weeks…
The post You Call That Unit Testing? – What Is It? appeared first on Davisbase Consulting.