2. Overview of this presentation
● What is “coverage analysis”?
● Types of coverage
○ Statement
○ Branch
○ Condition coverage and MC/DC
● Tools and use of “coverage”
3. What is “coverage analysis” ?
- Find out how much of your program is “used” after running
(tests)
- Metrics for “usage”
- Statements
- Branches (e.g. if expressions)
- Conditions (e.g. all boolean ex. in an if statement)
- Typically used to see how much your tests “cover” your code.
- Can be used to find dead/useless code
4.
5.
6. Types of Code Coverage
Statements: Measure amount of executable lines used
Branch: Measure of all possible code paths taken
Conditions: Measure that all conditions (and combinations)
are used (and are relevant to the outcome of a branch)
7.
8. Expression A Expression B Expression C Result
TRUE TRUE TRUE TRUE
TRUE TRUE FALSE FALSE
TRUE FALSE TRUE TRUE
TRUE FALSE FALSE FALSE
FALSE TRUE TRUE TRUE
FALSE TRUE FALSE FALSE
FALSE FALSE TRUE FALSE
FALSE FALSE FALSE FALSE
9. Tools & “coverage”
Typically coverage analysis requires “instrumentation”
Codecov - https://codecov.io/ (integrates only with git repos)
coverage uses the python interpreter (Cython, Pypy, PyPy3)
to detect lines and branches used.
10. $ pip install coverage
$ coverage run -a --branch myprogram.py argfoo argbar
$ coverage run -a --branch myprogram.py argfoo argcov
$ coverage html # htmlcov/index.html (html report)
$ coverage report # plaintext report (same as in html)
Quick Start