In Control Structures That Every Programming Language Should Support, we listed essential programming structures. In this post, we will discuss code coverage based on those structures. The post is aligned with the Black Box Software Testing Foundations course (BBST) designed by Rebecca Fiedler, Cem Kaner, and James Bach.
We first need to define who is actually doing the coverage.
- This could be a dedicated program written in checking programming framework that is using a structural code coverage library for the automatic gathering of structural coverage reports.
- The tester exercises program under test as a black box. Structural code coverage reports are also automatically gathered using a dedicated library for that purpose.
We need to create test cases with test data and actions that will gather coverage metrics.
The first option is mostly used in practice.
Structural code coverage is coverage done by focusing on the control structures of the program.
Here are examples:
- Statement coverage — is every statement in a program executed IN ANY ORDER?
- Branch coverage — is every program STATEMENT and every BRANCH executed IN ANY ORDER? We stress the union of statements and branches. This is usually not stressed because every statement is executed for sure if we execute all branches.
- Loop coverage — did we execute all possible loops in the maximal number of repetitions?
- Multi-condition coverage — did we execute all combinations of logical expressions. Knowledge of Boolean arithmetic is the precondition for this.
IEEE Unit Testing standard (IEEE Std. 982.1–1988, § 4.17, “Minimal Unit Test Case Determination”) defines 100% Statement coverage and 100% branch coverage (note that latter includes former).
Complete structural code coverage does not imply complete testing. When you hear the word “coverage,” immediately ask for clarification on what that person means by coverage.
- Ammann & Offutt (2008), Introduction to Software Testing
- Jorgensen (2008, 3rd ed), Software Testing: A Craftsman’s Approach
Originally published at https://blog.tentamen.eu on January 27, 2020.