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
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.
Regards,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.