Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java code coverage without instrumentation

I'm trying to figure out which tool to use for getting code-coverage information for projects that are running in kind of stabilization environment. The projects are deployed as a war and running on Jboss. I need server-side coverage while running manual / automated tests interacting with a running server. Lets assume I cannot change projects' build and therefore cannot add any kind of instrumentation to their jars as part of the build process. I also don't have access to code.

I've made some reading on various tools and they are all presenting techniques involving instrumenting the jars on build (BTW - doesn't that affect production, or two kinds of outputs are generated?) One tool though, JaCoCo, mentioned "on-the-fly-instrumentation" feature. Can someone explain what does it mean? Can this help me with my limitations? I've also heard on code-coverage using runtime profiling techniques - can someone help on that issue?

Thanks, Ben

like image 242
Ben Bracha Avatar asked Nov 01 '11 16:11

Ben Bracha


2 Answers

AFAIK "on-the-fly-instrumentation" means that the coveragetool hooks into the Classloading-Mechanism by using a special ClassLoader and edits the Class-Bytecode when it's being loaded. The result should be the same as in "offline-instrumentation" with the JARs.

Have also a look at EMMA, which supports both mechanisms. There's also a Plugin for Eclipse.

like image 123
electrodraco Avatar answered Nov 04 '22 16:11

electrodraco


A possible solution to this problem without actual code instrumentation is to use a jvm c-agent. It is possible to attach agents to the jvm. In such an agent you can intercept every method call done in your java code without changes to the bytecodes.

At every intercepted method call you then write info about the method call which can be evaluated later for code coverage purposes.

Here you'l find the official guide to the JVMTI JVMTI which defines how jvm agents can be written.

like image 42
paweloque Avatar answered Nov 04 '22 16:11

paweloque