EclEmma 2.3.3/JaCoCo 0.7.5 shows 0% coverage for lambda that was actually 100%, why?

369 views
Skip to first unread message

da...@bakins-bits.com

unread,
Sep 22, 2015, 3:51:40 PM9/22/15
to JaCoCo and EclEmma Users, davi...@ispot.tv
I'm getting incorrect coverage information for a lambda used in a TestNG/AssertJ test. The EclEmma/JaCoCoo version is one I just installed from http://download.eclipselab.org/eclemma/trunk/update into Eclipse 4.5 - EclEmma 2.3.3.201509111100, JaCoCo 0.7.5.201505241946. TestNG 6.9.6, AssertJ 3.1.0.

Here's the test code:

package com.bakins_bits;

import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.*;

@Test(enabled = true)
public class TestPlaypen
{
public void coverage_with_EclEmma_and_lambdas_and_AssertJ_helper() {
String s = "abcd".toUpperCase();
assertThat(s).isEqualTo("ABCD");
throw new RuntimeException("boo!");
}

@Test
public void coverage_with_EclEmma_and_lambdas_and_AssertJ() {
assertThatThrownBy(() -> {
coverage_with_EclEmma_and_lambdas_and_AssertJ_helper();
}).isInstanceOf(RuntimeException.class);
}
}

TL;DR: The lambda shows in red and at 0% coverage in the exported HTML report. I would expect it to show green and 100% (given that this version of EclEmma/JaCoCo supports lambdas).

Details:

The color-coded coverage results in the text editor window show the body of coverage_with_EclEmma_and_lambdas_and_AssertJ_helper() in green, also the
assertThatThrownBy line in coverage_with_EclEmma_and_lambdas_and_AssertJ(). The call of coverage_with_EclEmma_and_lambdas_and_AssertJ_helper() is RED and the
isInstanceOf(...) line is yellow. I would have expected it all to be green.

The report view window is somewhat better: Drilling down to the two coverage_with_EclEmma_and_lambdas_and_AssertJ.* routines shows 100% coverage of instructions. But the parent TestPlaypen shows only 88.5% coverage with some missed instructions.

Finally, the exported HTML report shows coverage_with_EclEmma_and_lambdas_and_AssertJ.* and TestPlaypen at 100% coverage but lambda$0() at 0%.

Thanks! -- David Bakin

Marc R. Hoffmann

unread,
Sep 23, 2015, 3:08:59 PM9/23/15
to jac...@googlegroups.com
Hi David,

thanks for the detailed analysis. The root caus here is not specific to lambda at all. The line
  coverage_with_EclEmma_and_lambdas_and_AssertJ_helper();
terminates with a implicit exception. By its design it is a know limitation of EclEmma that such lines are marked as not covered. You can verify that the line stays red even if called outside a lambda expression.

See FAQ: http://eclemma.org/jacoco/trunk/doc/faq.html

Source code lines with exceptions show 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 the corresponding line of source code is not marked as covered.

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