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


On 22.09.15 21:51, [email protected] wrote:
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


--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/5602F8C7.101%40mountainminds.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to