In my case, some testing frameworks based bytecode like Robolectric, need 
to keep compatible with JaCoCo. And it handles carefully  by detecting 
JaCoCo instrumented.

https://github.com/robolectric/robolectric/issues/8001

Is there any ways to check if a class was instrumented by JaCoCo?

I came up with a possible solution based on JaCoCo docs and implementation. 
Like:

Checking jacoco instrument by if there are two members in class with being 
mared as synthetic:
- private static field with naming $jacocoData
- private static method with naming $jacocoInit

According to the JaCoCo docs:

> To collect execution data JaCoCo instruments the classes under test which 
adds two members to the classes: A private static field $jacocoData and a 
private static method $jacocoInit(). Both members are marked as synthetic.

See https://www.eclemma.org/jacoco/trunk/doc/faq.html

And both JaCoCo on-the-fly and offline instrument are sharing the same 
options, and they instrument code in class granularity. It means that once 
a class is to be instrumented, all methods of this class are instrumented.

https://www.jacoco.org/jacoco/trunk/doc/agent.html

IMO, are there any better ways to check?

Like, adding a field or flag in class like naming with `$jacocoInstrumented 
= true`.

-- 
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 jacoco+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/2d3f7455-ddc4-4889-b631-e0e8b955f34en%40googlegroups.com.

Reply via email to