Is unit testing an important aspect of software development?

Is unit testing an important aspect of software development?

Who performs unit testing and why is it important?

    Requires Free Membership to View

    When you register, you'll receive targeted emails designed to keep you informed of the most relevant information on Agile development, application security, testing & QA, software requirements, and more.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSoftwareQuality.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSoftwareQuality.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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.

This was first published in March 2010