Sonar + jacoco shows source file lines as uncovered while I'm sure they are covered

1,861 views
Skip to first unread message

vandeve...@gmail.com

unread,
Mar 20, 2013, 4:27:39 AM3/20/13
to jac...@googlegroups.com
I know these lines are covered, because otherwise the test would have failed.
Context: I'm using a multi-module maven project, where a dedicated integration tests module is targeting the core module. For the setup I followed the instructions from the 'code-coverage' sonarsource example, obtained from https://github.com/SonarSource/sonar-examples. My root pom has a jacoco-maven-plugin configuration causing all modules to generate a report for their unit tests, and the integration test module pom overrides this configuration with
---
<configuration>
<destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
</configuration>
<executions><execution>
<id>post-test</id>
<configuration><skip>true</skip></configuration>
</execution></executions>
---
Somehow sonar uses the thus generated jacoco-it.exec file to get the data for its integration test widget. How can I find out why sonar+jacoco claims that some lines are not covered, while I know they are?

Marc Hoffmann

unread,
Mar 20, 2013, 6:17:48 AM3/20/13
to jac...@googlegroups.com
Regarding JaCoCo there are a couple of possible reasons, see FAQ:

http://www.eclemma.org/jacoco/trunk/doc/faq.html

Especially: "Code with exceptions shows no coverage. Why?

JaCoCo determines code execution with so called probes. Probes are
inserted into the control flow at certain positions. Code is considered
as executed when a subsequent probe has been executed. In case of
exceptions such a sequence of instructions is aborted somewhere in the
middle and not marked as executed."

Does the class in question show any coverage at all?

Best regards,
-marc

Erik Vande Velde

unread,
Mar 20, 2013, 11:55:59 AM3/20/13
to jac...@googlegroups.com
The class always shows some coverage, but it's what I tend to call a 'flip flop'. Sometimes it reports a coverage of 48%, sometimes the class is not listed. In the second case the coverage is up to 100%, sonar doesn't show such 'perfectly covered' classes.
Is there any way to look at the inside my generated jacoco-it.exec file? I even don't know enough of jacoco to understand if this exec is a real executable (as the name seems to imply) or a data file. The trouble is that my normal modules create reports in their target\site\jacoco directory, but the integration test module just produces the jacoco-it.exec without a corresponding report.

Marc Hoffmann

unread,
Mar 20, 2013, 12:53:48 PM3/20/13
to jac...@googlegroups.com
> Is there any way to look at the inside my generated jacoco-it.exec
> file?

There is:

- If you have EclEmma installed you can open *.exec files in Eclipse
- If you don't use Eclipse you can run the ExecDump.java example
(http://www.eclemma.org/jacoco/trunk/doc/api.html)

Cheers,
-marc

On 2013-03-20 16:55, Erik Vande Velde wrote:
> The class always shows some coverage, but it's what I tend to call a
> 'flip flop'. Sometimes it reports a coverage of 48%, sometimes the
> class is not listed. In the second case the coverage is up to 100%,
> sonar doesn't show such 'perfectly covered' classes.
> Is there any way to look at the inside my generated jacoco-it.exec
> file? I even don't know enough of jacoco to understand if this exec
> is
> a real executable (as the name seems to imply) or a data file. The
> trouble is that my normal modules create reports in their
> targetsitejacoco directory, but the integration test module just
> produces the jacoco-it.exec without a corresponding report.
>
> On Wednesday, March 20, 2013 11:17:48 AM UTC+1, Marc R. Hoffmann
> wrote:
>
>> Regarding JaCoCo there are a couple of possible reasons, see FAQ:
>>
>> http://www.eclemma.org/jacoco/trunk/doc/faq.html [1]
>>
>> Especially: "Code with exceptions shows no coverage. Why?
>>
>> JaCoCo determines code execution with so called probes. Probes are
>> inserted into the control flow at certain positions. Code is
>> considered
>> as executed when a subsequent probe has been executed. In case of
>> exceptions such a sequence of instructions is aborted somewhere in
>> the
>> middle and not marked as executed."
>>
>> Does the class in question show any coverage at all?
>>
>> Best regards,
>> -marc
>>
>> On 2013-03-20 09:27, vandeve...@gmail.com wrote:
>>> I know these lines are covered, because otherwise the test would
>> have
>>> failed.
>>> Context: I'm using a multi-module maven project, where a dedicated
>>
>>> integration tests module is targeting the core module. For the
>> setup
>>> I
>>> followed the instructions from the 'code-coverage' sonarsource
>>> example, obtained from
>> https://github.com/SonarSource/sonar-examples [2].
>>> My root pom has a jacoco-maven-plugin configuration causing all
>>> modules to generate a report for their unit tests, and the
>>> integration
>>> test module pom overrides this configuration with
>>> ---
>>> <configuration>
>>> <destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
>>> </configuration>
>>> <executions><execution>
>>> <id>post-test</id>
>>> <configuration><skip>true</skip></configuration>
>>> </execution></executions>
>>> ---
>>> Somehow sonar uses the thus generated jacoco-it.exec file to get
>> the
>>> data for its integration test widget. How can I find out why
>>> sonar+jacoco claims that some lines are not covered, while I know
>>> they
>>> are?
>
> --
> You received this message because you are subscribed to the Google
> Groups "JaCoCo and EclEmma Users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to jacoco+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out
> [3].
>
>
>
> Links:
> ------
> [1] http://www.eclemma.org/jacoco/trunk/doc/faq.html
> [2] https://github.com/SonarSource/sonar-examples
> [3] https://groups.google.com/groups/opt_out

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