blob: 7197ba008a144190a56d488bbc453c7638dbddf7 [file] [log] [blame]
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +00001<?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. Hoffmannd7d2f752010-05-06 21:12:31 +00007 <link rel="shortcut icon" href=".resources/report.gif" type="image/gif" />
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +00008 <title>JaCoCo - Coverage Counter</title>
9</head>
10<body>
11
12<div class="breadcrumb">
Marc R. Hoffmannd7d2f752010-05-06 21:12:31 +000013 <a href="../index.html" class="el_report">JaCoCo</a> &gt;
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +000014 <a href="index.html" class="el_group">Documentation</a> &gt;
15 <span class="el_source">Coverage Counters</span>
16</div>
Marc R. Hoffmann17be2692010-02-02 05:44:47 +000017<div id="content">
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +000018
19<h1>Coverage Counters</h1>
20
21<p>
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000022 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. Hoffmannc4b20782009-10-02 13:28:46 +000034</p>
35
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000036<h2>Instructions (C0 Coverage)</h2>
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +000037
38<p>
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000039 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. Hoffmannc4b20782009-10-02 13:28:46 +000059</p>
60
61<ul>
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000062 <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. Hoffmannc4b20782009-10-02 13:28:46 +000066</ul>
67
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +000068<h2>Lines</h2>
69
70<p>
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000071 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. Hoffmannc4b20782009-10-02 13:28:46 +000075</p>
76
77<p>
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000078 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. Hoffmannc4b20782009-10-02 13:28:46 +000081</p>
82
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000083<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. Hoffmannc4b20782009-10-02 13:28:46 +000092<h2>Methods</h2>
93
94<p>
Marc R. Hoffmann2593f032010-12-20 18:28:34 +000095 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. Hoffmannc4b20782009-10-02 13:28:46 +0000101</p>
102
103<h2>Classes</h2>
104
105<p>
Radek Libaad5fbc92009-10-26 13:26:53 +0000106 A class is considered as executed when at least one of its methods has been
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +0000107 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. Hoffmann17be2692010-02-02 05:44:47 +0000112</div>
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +0000113<div class="footer">
Marc R. Hoffmannb623ffb2010-05-06 19:48:08 +0000114 <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span>
Marc R. Hoffmanndf6ff962010-04-09 15:31:22 +0000115 <a href="license.html">Copyright</a> &copy; @copyright.years@ Mountainminds GmbH &amp; Co. KG and Contributors
Marc R. Hoffmannc4b20782009-10-02 13:28:46 +0000116</div>
117
118</body>
119</html>