Dear all,

JaCoCo does not detect that certain instructions are run (covered) if these 
lead to an implicit exception. In the following example, if c() throws an 
exception, the result indicate no coverage for b().

public void foo() {
 a();
 try {
    b();
    c();
 } catch (Throwable t) {}
}

In the following example, no coverage at all is reported, assuming c() again 
throws an exception.

public void bar() {
  a();
  b();
  c();
}

Note that the last example is quite common when writing JUnit 4 tests using the 
"expected" keyword, as in the following example.

@Test(expected=SomeException.class)
public void testBar() {
   ...
}

I experimented with adding more probes inserted in front of opcodes that may 
thrown an (implicit) exception. With such probes more precise coverage results 
are obtained, at the cost of having more probes. This means a slower execution 
(analysis) speed, and bigger instrumented class files.

In my _preliminary_ experiments I see about 1-2% of increased coverage, if 
coverage of the Test classes is included in the report. This comes at the cost 
of about 1% more runtime when compared to the current release of JaCoCo.

I am now interested in your opinions on this. Do you think having a more 
precise analysis as described is worthwhile? Should the feature be in JaCoCo, 
or not? Should it be configurable, possibly disabled by default?

On a more technical note, it is possible to only add probes for some of the 
opcodes which may thrown an exception. For example, one could add probes for 
INVOKE opcodes (which would help with the JUnit tests, based on my experience), 
and not add probes for PUTFIELD and array opcodes.

Best regards,
Carsten

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to