Code coverage

In software engineering, code coverage, also called test coverage, is a percentage measure of the degree to which the source code of a program is executed when a particular test suite is run.

Code coverage was among the first methods invented for systematic software testing.

[3] To measure what percentage of code has been executed by a test suite, one or more coverage criteria are used.

For example, consider the following Pascal code fragment: Condition coverage can be satisfied by two tests: However, this set of tests does not satisfy branch coverage since neither case will meet the if condition.

Fault injection may be necessary to ensure that all conditions and branches of exception-handling code have adequate coverage during testing.

However, for safety-critical applications (such as avionics software) it is often required that modified condition/decision coverage (MC/DC) be satisfied.

This criterion extends condition/decision criteria with requirements that each condition should affect the decision outcome independently.

[11] However, setting specific target values - and, in particular, 100% - has been criticized by practitioners for various reasons (cf.

[citation needed][clarification needed] The target software is built with special options or libraries and run under a controlled environment, to map every executed function to the function points in the source code.

Edge coverage reports which branches or code decision points were executed to complete the test.

Generally, test coverage tools incur computation and logging in addition to the actual program thereby slowing down the application, so typically this analysis is not done in production.

In particular, some race conditions or similar real time sensitive operations can be masked when run under test environments; though conversely, some of these defects may become easier to find as a result of the additional overhead of the testing code.

[17] Test coverage is one consideration in the safety certification of avionics equipment.

The guidelines by which avionics gear is certified by the Federal Aviation Administration (FAA) is documented in DO-178B[16] and DO-178C.