0% found this document useful (0 votes)
128 views

Java Code Coverage Tools - Eclemma and Jacoco

This document discusses Java code coverage tools EclEmma and JaCoCo. It explains that code coverage measures how well a test suite tests an application by determining which parts of the code are executed by the tests. EclEmma is an Eclipse plugin that measures Java code coverage and works with test frameworks like JUnit. JaCoCo is a code coverage library that instruments Java bytecode to collect execution data. The document provides instructions on installing EclEmma and examples of using it to view code coverage in Eclipse.

Uploaded by

rajasekhar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Java Code Coverage Tools - Eclemma and Jacoco

This document discusses Java code coverage tools EclEmma and JaCoCo. It explains that code coverage measures how well a test suite tests an application by determining which parts of the code are executed by the tests. EclEmma is an Eclipse plugin that measures Java code coverage and works with test frameworks like JUnit. JaCoCo is a code coverage library that instruments Java bytecode to collect execution data. The document provides instructions on installing EclEmma and examples of using it to view code coverage in Eclipse.

Uploaded by

rajasekhar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

/ 10

Java Code Coverage Tools


- EclEmma and JaCoCo
05/01/2020 Java MUSE Implementation 2 / 10

Introduction: Coverage-Based Testing


• Code coverage measures quality of test suite.

• An element is covered if a test suite executes/makes a behavior for the element.


 A class is covered if a test suite accesses the class.
 A method is covered if a test suite invokes the method.
 A statement is covered if a test suite executes the statement.
 A branch is covered if a test suite follows the branch.
 A instruction is covered if a test suite executes the instruction.

• If a test suite does not an element, errors in the element cannot be found by the
test suite.
 The higher test suite coverage, the more errors is likely to be found.
05/01/2020 Java MUSE Implementation 3 / 10

Coverage Measurement Tools


• There are tools to measure coverage in many languages.
 C – gcov
 C++ - …
 Java – EclEmma(JaCoCo)
• We will look into EclEmma and JaCoCo for SafeHome project.
 EclEmma is an Eclipse plugin that measures Java code coverage.
 JaCoCo is Java code coverage library developed by EclEmma project team.
 See http://www.eclemma.org/
 See http://www.eclemma.org/jacoco/index.html
• EclEmma can be used with JUnit, TestNG, and so on.
 They are Java test frameworks.
 JUnit is provided in Eclipse as well.
05/01/2020 Java MUSE Implementation 4 / 10

EclEmma – Measuring Coverage in Eclipse Example (1/3)


• Target project: SafeHomeDevice.zip
 1. Execute SafeHomeDevice with EclEmma.
 2. Click control panel.
 3. Click button 1.
 4. Terminate the application.
 5. (Cont.)
05/01/2020 Java MUSE Implementation 5 / 10

EclEmma – Measuring Coverage in Eclipse Example (2/3)


 5. Check DeviceControlPanelAbstract.java:244. Eclipse shows coverage status like the following.

• Yellow line is partially covered.


 Only parts of Bytecode instructions are covered or,
 A branch is not completely covered.
• Green line is fully covered.
• Red line is not covered.
• Test suite coverage is union of each test case coverage.
 EclEmma supports merging coverage measurement of test case.
 EclEmma manages ‘session’s. session represents coverage measurement.
05/01/2020 Java MUSE Implementation 6 / 10

EclEmma – Measuring Coverage in Eclipse Example (3/3)


05/01/2020 Java MUSE Implementation 7 / 10

EclEmma Installation & Configuration (1/3)


• From http://www.eclemma.org/installation.html

• In Eclipse, Help->Install New Software…


• Type http://update.eclemma.org at “Work with:” field.
• Select and install EclEmma.

• You may see application launch options provided EclEmma.


05/01/2020 Java MUSE Implementation 8 / 10

EclEmma Installation & Configuration (2/3)


• You can configure launch options as default launcher provided in Eclipse.
05/01/2020 Java MUSE Implementation 9 / 10

EclEmma Installation & Configuration (3/3)


• Go to Window->Show view->other->Java. And, select Coverage. Then, you can s
ee coverage status window.

• You can check coverage measurement, manage coverage data and export data in
HTML format.
 See report template in http://www.eclemma.org/jacoco/trunk/coverage/.
05/01/2020 Java MUSE Implementation 10 / 10

JaCoCo – Java Code Coverage Library


• JaCoCo provides coverage measurement by load-time instrumentation.

• When executing JVM, use –javaagent arguments to use JaCoCo.


 JaCoCo will generate jacoco.exec which contains execution data.
 JaCoCo provides library to generate coverage reports using jacoco.exec.
• See http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java.
 EclEmma can import jacoco.exec generated by JaCoCo into a session.

• There are various options using JaCoCo. See http://


www.eclemma.org/jacoco/trunk/doc/agent.html.
05/01/2020 Java MUSE Implementation 11 / 10

Demo
• 1. SafeHomeDevice
• 2. Triangle

You might also like