Java Code Coverage Tools - EclEmma and JaCoCo
Code coverage is vital for assessing the quality of a test suite. Different levels of coverage, such as class, method, statement, branch, and instruction, provide insight into the thoroughness of testing. EclEmma and JaCoCo are tools commonly used for measuring Java code coverage. EclEmma, an Eclipse plugin, offers seamless integration with Java test frameworks like JUnit and TestNG, while JaCoCo is a Java code coverage library developed by the EclEmma team. This implementation discusses the importance of coverage-based testing and provides a practical example of measuring coverage in Eclipse using EclEmma. Detailed steps for installing and configuring EclEmma within Eclipse are also outlined.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
/ 10 Java Code Coverage Tools - EclEmma and JaCoCo
2025-03-08 Java MUSE Implementation 1 / 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.
2025-03-08 Java MUSE Implementation 2 / 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.
2025-03-08 Java MUSE Implementation 3 / 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.)
2025-03-08 Java MUSE Implementation 4 / 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.
2025-03-08 Java MUSE Implementation 5 / 10 EclEmma Measuring Coverage in Eclipse Example (3/3)
2025-03-08 Java MUSE Implementation 6 / 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.
2025-03-08 Java MUSE Implementation 7 / 10 EclEmma Installation & Configuration (2/3) You can configure launch options as default launcher provided in Eclipse.
2025-03-08 Java MUSE Implementation 8 / 10 EclEmma Installation & Configuration (3/3) Go to Window->Show view->other->Java. And, select Coverage. Then, you can see 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/.
2025-03-08 Java MUSE Implementation 9 / 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.
2025-03-08 Java MUSE Implementation 10 / 10 Demo 1. SafeHomeDevice 2. Triangle