Search⌘ K

Unit Test Coverage: Concepts and Techniques

Explore the concepts of unit test coverage, focusing on branch coverage as a key measure of testing completeness. Understand how to design tests that maximize code coverage using edge cases and varied inputs. Learn about various code coverage tools and the difference between branch and statement coverage to ensure effective and comprehensive testing.

Introduction

Test coverage is a measure of the degree to which application code is executed when test code is run. Test code may enhance test coverage by increasing the branch coverage of the application code. Branch coverage is the ratio of the number of executed branches in an application code’s control structure and the total number of branches in control structures. Control structures include selection statements and iteration statements. Selection statements include the if, if else, and switch statements. Iteration statements include the do, for, for each, and while statements.

You can think of branch coverage qualitatively and quantitatively. Its quantitative measurement is given by the following formula:

Branch coverage=Branches t ...