Problem solve Get help with specific problems with your technologies, process and projects.

Is unit testing an important aspect of software development?

Unit testing can be very helpful in testing source code while an application is being built by catching bugs early in the development cycle and easing testers' workloads.

Who performs unit testing and why is it important?

Unit testing is testing that is performed on the application source code, typically by the developer who wrote the code. This type of testing is considered "white-box" testing -- the tests are performed with full knowledge of the source code. Ideally, a developer would be able to run unit tests so that all the code paths would be executed as a result of the testing. In other words, the unit tests would need to create the conditions to go through each line of code to ensure all the code was operating correctly.

Another form of unit testing that is used in agile environments is test-driven development (TDD). In this case, the tests are written before the code is written. The tests verify certain assertions that are agreed upon as acceptance criteria. The tests will initially fail until the code is written which, when executed, will satisfy the acceptance criteria and cause the tests to pass. These types of tests are typically automated and serve to define the requirements of the system as well as provide automated unit tests that can be run with each build allowing for regression testing as changes are added to the system.

Unit testing is important because it is one of the earliest testing efforts performed on the code and the earlier defects are detected, the easier they are to fix. Early bug-detection is also the most cost-effective for a project, with code fixes becoming more expensive the later they're found in the lifecycle.

Though traditionally developers are responsible for unit testing the code they write, there has been some criticism that a developer may miss an issue both with the code and the test. For example, if the developer has misunderstood a requirement, both the code and the test are likely to be wrong. An objective tester may see areas of exposure where the developer has a blind eye. Sometimes developers work in pairs during the development cycle so that they can check one-another throughout the lifecycle, including during the unit test phase. Pair programmers work as a team and both share in the creation and unit testing of the code.

Dig Deeper on Topics Archive

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

I would say that unit testing is an absolutely essential part of software development. Ideally, unit tests should cover a very high percentage of code, if not 100%.