Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 1 | <?xml version="1.0" encoding="ISO-8859-1" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
| 4 | <head>
|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
|
| 6 | <link rel="stylesheet" href=".resources/doc.css" charset="ISO-8859-1" type="text/css" />
|
Marc R. Hoffmann | d7d2f75 | 2010-05-06 21:12:31 +0000 | [diff] [blame] | 7 | <link rel="shortcut icon" href=".resources/report.gif" type="image/gif" />
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 8 | <title>JaCoCo - Coverage Counter</title>
|
| 9 | </head>
|
| 10 | <body>
|
| 11 |
|
| 12 | <div class="breadcrumb">
|
Marc R. Hoffmann | d7d2f75 | 2010-05-06 21:12:31 +0000 | [diff] [blame] | 13 | <a href="../index.html" class="el_report">JaCoCo</a> >
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 14 | <a href="index.html" class="el_group">Documentation</a> >
|
| 15 | <span class="el_source">Coverage Counters</span>
|
| 16 | </div>
|
Marc R. Hoffmann | 17be269 | 2010-02-02 05:44:47 +0000 | [diff] [blame] | 17 | <div id="content">
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 18 |
|
| 19 | <h1>Coverage Counters</h1>
|
| 20 |
|
| 21 | <p>
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 22 | JaCoCo uses a set of different counters to calculate coverage metrics. All
|
| 23 | these counters are derived from information contained in Java class files
|
| 24 | which basically are Java byte code instructions and debug information
|
| 25 | optionally embedded in class files. This approach allows efficient on-the-fly
|
| 26 | instrumentation and analysis of applications even when no source code is
|
| 27 | available. In most cases the collected information can be mapped back to
|
| 28 | source code and visualized down to line level granularity. Anyhow there are
|
| 29 | limitations to this approach. The class files have to be compiled with debug
|
| 30 | information to calculate line level coverage and provide source highlighting.
|
| 31 | Not all Java language constructs can be directly compiled to corresponding
|
| 32 | byte code. In such cases the Java compiler creates so called <i>synthetic</i>
|
| 33 | code which sometimes results in unexpected code coverage results.
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 34 | </p>
|
| 35 |
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 36 | <h2>Instructions (C0 Coverage)</h2>
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 37 |
|
| 38 | <p>
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 39 | The smallest unit JaCoCo counts are single Java byte code instructions.
|
| 40 | <i>Instruction coverage</i> provides information about the amount of code that
|
| 41 | has been executed or missed. This metric is completely independent from source
|
| 42 | formatting and always available, even in absence of debug information in the
|
| 43 | class files.
|
| 44 | </p>
|
| 45 |
|
| 46 | <h2>Branches (C1 Coverage)</h2>
|
| 47 |
|
| 48 | <p>
|
| 49 | JaCoCo also calculates <i>branch coverage</i> for all <code>if</code> and
|
| 50 | <code>switch</code> statements. This metric counts the total number of such
|
| 51 | branches in a method and determines the number of executed or missed branches.
|
| 52 | Branch coverage is always available, even in absence of debug information in
|
| 53 | the class files.
|
| 54 | </p>
|
| 55 |
|
| 56 | <p>
|
| 57 | If the class files haven been compiled with debug information decision points
|
| 58 | can be mapped to source lines and hightighted accordingly:
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 59 | </p>
|
| 60 |
|
| 61 | <ul>
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 62 | <li>No coverage: No branches in the line has been executed (red diamond)</li>
|
| 63 | <li>Partial coverage: Only a part of the branches in the line have been
|
| 64 | executed (yellow diamond)</li>
|
| 65 | <li>Full coverage: All branches in the line have been executed (green diamond)</li>
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 66 | </ul>
|
| 67 |
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 68 | <h2>Lines</h2>
|
| 69 |
|
| 70 | <p>
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 71 | For all class files that have been compiled with debug information, coverage
|
| 72 | information for individual lines can be calculated. A source line is
|
| 73 | considered executed when at least one instruction that is assigned to this
|
| 74 | line has been executed.
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 75 | </p>
|
| 76 |
|
| 77 | <p>
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 78 | Due to the fact that a single line typically compiles to multiple byte code
|
| 79 | instructions the source code highlighting shows three different status for
|
| 80 | each line containing source code:
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 81 | </p>
|
| 82 |
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 83 | <ul>
|
| 84 | <li>No coverage: No instruction in the line has been executed (red
|
| 85 | background)</li>
|
| 86 | <li>Partial coverage: Only a part of the instruction in the line have been
|
| 87 | executed (yellow background)</li>
|
| 88 | <li>Full coverage: All instructions in the line have been executed (green
|
| 89 | background)</li>
|
| 90 | </ul>
|
| 91 |
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 92 | <h2>Methods</h2>
|
| 93 |
|
| 94 | <p>
|
Marc R. Hoffmann | 2593f03 | 2010-12-20 18:28:34 +0000 | [diff] [blame^] | 95 | Each non-abstract method contains at least one instruction. A method is
|
| 96 | considered as executed when at least one instruction has been executed. As
|
| 97 | JaCoCo works on byte code level also constructors and static initializers are
|
| 98 | counted as methods. Some of these methods may not have a direct correspondence
|
| 99 | in Java source code, like implicit and thus generated default constructors or
|
| 100 | initializers for constants.
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 101 | </p>
|
| 102 |
|
| 103 | <h2>Classes</h2>
|
| 104 |
|
| 105 | <p>
|
Radek Liba | ad5fbc9 | 2009-10-26 13:26:53 +0000 | [diff] [blame] | 106 | A class is considered as executed when at least one of its methods has been
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 107 | executed. Note that JaCoCo considers constructors as well as static
|
| 108 | initializers as methods. As Java interface types may contain static
|
| 109 | initializers such interfaces are also considered as executable classes.
|
| 110 | </p>
|
| 111 |
|
Marc R. Hoffmann | 17be269 | 2010-02-02 05:44:47 +0000 | [diff] [blame] | 112 | </div>
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 113 | <div class="footer">
|
Marc R. Hoffmann | b623ffb | 2010-05-06 19:48:08 +0000 | [diff] [blame] | 114 | <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span>
|
Marc R. Hoffmann | df6ff96 | 2010-04-09 15:31:22 +0000 | [diff] [blame] | 115 | <a href="license.html">Copyright</a> © @copyright.years@ Mountainminds GmbH & Co. KG and Contributors
|
Marc R. Hoffmann | c4b2078 | 2009-10-02 13:28:46 +0000 | [diff] [blame] | 116 | </div>
|
| 117 |
|
| 118 | </body>
|
| 119 | </html> |