How to only start gathering coverage data after a certain point in the code?

34 views
Skip to first unread message

Koen De Groote

unread,
Jun 11, 2017, 6:34:41 PM6/11/17
to JaCoCo and EclEmma Users
I have looked at the documentation and found nothing that sounds like this, so I came here.

I have some unit tests that work by first populating an in-memory database, using objects I create during the `@Before` part of the unit test.

The downside is that JaCoCo's reports are showing that the code in the constructor for those classes has been traversed, while actually the test itself, which happens after the database population, didn't access that code.

So, is there a way to overcome this with only JaCoCo or shall I have to do something else to avoid this issue?

Evgeny Mandrikov

unread,
Jun 12, 2017, 6:48:58 AM6/12/17
to JaCoCo and EclEmma Users
Since constructors was actually executed, JaCoCo as any other coverage tools shows them as executed. Don't know why you want to overcome this, but as a way to do this - you can reset the data collected by JaCoCo before execution of test via http://www.jacoco.org/jacoco/trunk/doc/api/org/jacoco/agent/rt/IAgent.html#getExecutionData(boolean) obtained via http://www.jacoco.org/jacoco/trunk/doc/api/org/jacoco/agent/rt/RT.html#getAgent() . This will probably require explicit saving of data at the end of test(s) via http://www.jacoco.org/jacoco/trunk/doc/api/org/jacoco/agent/rt/IAgent.html#dump(boolean) so that it won't be lost when next test-suite resets the data. Since this creates dependency from tests on coverage library, be careful to protect all this from a situation when tests executed without coverage library, e.g. by doing this from custom pluggable JUnit Listener.

Koen De Groote

unread,
Jun 12, 2017, 10:54:44 AM6/12/17
to JaCoCo and EclEmma Users
Thanks, I'll look into this.

As to why: because the population of the database isn't what's being tested. So anything that happens during that phase should not be recorded, as to not create an impression that something was covered while it was actually just the database population.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages