Generating an empty coverage report for a maven module/project with no tests

1,355 views
Skip to first unread message

inbox.c...@gmail.com

unread,
Mar 19, 2019, 11:31:04 AM3/19/19
to JaCoCo and EclEmma Users
Hi all, something of a convoluted question here.

Is there any way I can generate an "empty" or "all red" coverage report, even when no code in a project has been called?

I'll share my use case so that this hopefully makes more sense. I'm using maven and the jacoco-maven-plugin.

Internally, the team I work for has a maven plugin that calculates how much coverage a given GitHub pull request has. We don't want to check the code coverage of the project as a whole as some of them are legacy projects with close to 0% and we just want to enforce the adding of tests for new changes. Our method is as follows: we check the git diff vs master, see which lines of which files in this diff appear in some coverage report and then figure out what percentage of those has code coverage.

Here is the current issue we are having: there is one project in a particularly bad state with literally zero tests. Since there are no tests, no jacoco.exec file is output at the end of the maven test lifecycle, so no report is generated. This obviously makes sense since a module could be config or some other non-java code that jacoco is not interested in. However, in our case we are left with no way of determining which lines are executable in the project and therefore default to thinking it is not coverable meaning that until at least one test is added, all PRs will pass our checks.

Is there any way to force the creation of a jacoco.exec file that just says there were no lines covered at all? Is this option exposed in the jacoco maven plugin?

Thanks,
K

Evgeny Mandrikov

unread,
Mar 19, 2019, 12:00:48 PM3/19/19
to JaCoCo and EclEmma Users

On Tuesday, March 19, 2019 at 4:31:04 PM UTC+1, inbox.c...@gmail.com wrote: 
Is this option exposed in the jacoco maven plugin?

All configuration parameters are listed in documentation - https://www.jacoco.org/jacoco/trunk/doc/report-mojo.html
Furthermore all source code of jacoco-maven-plugin is also available - https://github.com/jacoco/jacoco/tree/master/jacoco-maven-plugin

Is there any way to force the creation of a jacoco.exec file that just says there were no lines covered at all?


Just create literally empty "jacoco.exec" file.

Or even simpler - just create literally empty test, so that it will be executed and "jacoco.exec" will be created for you:

public class FakeTest {
  @org.junit.Test
  public void empty() {
  }
}

inbox.c...@gmail.com

unread,
Mar 22, 2019, 8:26:36 AM3/22/19
to JaCoCo and EclEmma Users
Thanks for taking the time to reply Evgeny.

The fake test solution was the first thing we tried, and found that ti didn't work unless we explicitly called code in the module within the test. A dummy test was not enough to force a report to be generated.

In the end we decided to go with adding some flags to the parent pom the 100 or so projects inherit from that fails if a module doesn't have tests.

Leaving this reply just so any future searchers can come across it.

Evgeny Mandrikov

unread,
Mar 22, 2019, 9:51:41 AM3/22/19
to JaCoCo and EclEmma Users


On Friday, March 22, 2019 at 1:26:36 PM UTC+1, inbox.c...@gmail.com wrote:
The fake test solution was the first thing we tried, and found that ti didn't work unless we explicitly called code in the module within the test. A dummy test was not enough to force a report to be generated.

No idea what exactly you tried - example in attachment demonstrates that this works.

example.zip
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages