Unit Testing & Code coverage

“When writing the code, think of the test.

When writing the test, think of the code.

When you think of code and test as one,

Testing is easy and code is beautiful”

In software programming, testing is one of the most indispensable aspects. Testing is a process to investigate if the objectives defined by the stakeholders are met and the quality of the software is of high standard. Test techniques includes various processes, which are defined to execute the application to test its fitment for use.

Unit Testing is one such technique that is performed by developers where individual components/unit of a software is tested. The purpose is to validate that the each unit of the software performs the task as designed. A unit is the smallest piece of software that can be tested. It can be either a program, function or a procedure. With modern day development methodology like Test Driven Development(TDD), that takes meticulous approach of building software by means of continuous testing and revision, unit testing becomes all the more crucial.

However, how do we ascertain that the unit tests that we have written are covering all grounds? Is there a way to validate that all pieces of the software are fully tested?

To solve this, we have measures like code coverage that is used to define the degree to which a software application is executed when the test suits are executed. An application with high coverage, measured as a percentage value, has more areas of code executed during testing and is comparatively less vulnerable to undetected bugs than an application with low value of test coverage percentage. Test coverage clearly gives a comfort that before the product is shipped maximum pieces of the software are tested and are performing as expected.

So does this mean that we should have a code coverage of 100%? Now that’s a tricky one!

“Run your test often.

Don’t let them get stale.

Rejoice when they pass.

Rejoice when they fail.”

PS: The cryptic bits are taken from "The Way of Testivus" and can be found here

To view or add a comment, sign in

Others also viewed

Explore content categories