

JaCoCo Code Coverage and Report of multiple Eclipse plug-in projects
source link: http://www.lorenzobettini.it/2017/02/jacoco-code-coverage-and-report-of-multiple-eclipse-plug-in-projects/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

JaCoCo Code Coverage and Report of multiple Eclipse plug-in projects
In this tutorial I’ll show how to use Jacoco with Maven/Tycho to create a code coverage report of multiple Eclipse plug-in projects.
The code of the example is available here: https://github.com/LorenzoBettini/tycho-multiproject-jacoco-report-example.
This is the structure of the projects:
Each project’s code is tested in a specific .tests project. The code consists of simple Java classes doing nothing interesting, and tests just call that code.
The Maven parent pom file is written such that Jacoco is enabled only when the profile “jacoco” is explicitly activated:
This is just an example of configuration; you might want to tweak it as you see fit for your own projects (in this example I also created a Main.java with a main method that I exclude from the coverage). By default, the jacoco-maven-plugin will “prepare” the Jacoco agent in the property tycho.testArgLine (since our test projects are Maven projects with packaging eclipse-plugin-test); since tycho.testArgLine is automatically used by the tycho-surefire-plugin and since we have no special test configuration, the pom.xml of our test projects is just as simple as this:
if you need a custom configuration, then you have to explicitly mention ${tycho.testArgLine} in the <argLine>.
Now we want to create an aggregate Jacoco report for the classes in plugin1 and plugin2 projects (tested by plugin1.tests and plugin2.tests, respectively); each test project will generate a jacoco.exec file with coverage information. Before Jacoco 0.7.7, creating an aggregate report wasn’t that easy and required to store all coverage data in a single an .exec file and then use an ant task (with a manual configuration specifying all the source file and class file paths). In 0.7.7, the jacoco:report-aggregate has been added, which makes creating a report really easy!
Here’s an excerpt of the documentation:
Creates a structured code coverage report (HTML, XML, and CSV) from multiple projects within reactor. The report is created from all modules this project depends on. From those projects class and source files as well as JaCoCo execution data files will be collected. […] This also allows to create coverage reports when tests are in separate projects than the code under test. […]
Using the dependency scope allows to distinguish projects which contribute execution data but should not become part of the report:
compile
: Project source and execution data is included in the report.test
: Only execution data is considered for the report.
So it’s just a matter of creating a separate project (I called that example.tests.report) where we:
- configure the report-aggregate goal (in this example I bind that to the verify phase)
- add as dependencies with scope compile the projects containing the actual code and with scope test the projects containing the tests and .exec data
That’s all!
Now run this command in the example.parent project:
and when the build terminates, you’ll find the HTML code coverage report for all your projects in the directory (again, you can configure jacoco with a different output path, that’s just the default):
/example.tests.report/target/site/jacoco-aggregate
Since, besides the HTML report, jacoco will create an XML report, you can use any tool that keeps track of code coverage, like the online free solution Coveralls (https://coveralls.io/). Coveralls is automatically accessible from Travis (I assume that you know how to connect your github projects to Travis and Coveralls). So we just need to configure the coveralls-maven-plugin with the path of the Jacoco xml report (I’m doing this in the parent pom, in the pluginManagement section in the jacoco profile):
And here’s the Travis file:
This is the coveralls page for the example project https://coveralls.io/github/LorenzoBettini/tycho-multiproject-jacoco-report-example. And an example of coverage information:
That’s all!
Happy coverage!
Like this:
Recommend
-
144
The Trouble with JaCoCo: Lessons Learned 10.10.2017 by Fabian Streitel & Fabian Streitel When we set up the
-
67
README.md JaCoCo Java Code Coverage Library
-
18
java-version.com: What's new in Java 16? 15? Keep up to date! JMockit with Maven, Sonar, JaCoCo and Jenkins/Hudson
-
11
Reporting Code Coverage using Maven and JaCoCo plugin1. INTRODUCTION Code coverage is a metric indicating which percentage of lines of code are executed when running automated tests.
-
7
This episode is going to be all about testing and code coverage 🧪 as we have Evgeny Mandrikov on stage! He’s going to tell use the story behind
-
15
在Java技术栈上,基本上提到覆盖率,大家就会想到JaCoco「Java Code Coverage的缩写」,几乎所有的覆盖率项目,都是使用JaCoco,可想而知它的影响力有多大,我们在Android项目中,也集成了JaCoco,官网文档如下。
-
3
0:00 / 2:01:03 ...
-
5
Combining Code Coverage Data From Multiple Testing Tools When we test our applications, it’s often useful to use more than one tool or framework for different kinds of tests. For exa...
-
4
1. INTRODUCTION SonarQube is a widely adopted tool that collects, analyses, aggregates and reports the source code quality of your applications. It helps teams to measure the quality of the source code as your a...
-
4
azizutku/jacoco-aggregate-coverage-plugin: Unified JaCoCo Code Coverage Plugin for Multi Module Projects main ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK