Once again: *agent should be attached to the JVM that executes application whose coverage should be measured.*
Task "coverage" configures nested tasks that start Java to use agent. Instrumentation is performed by agent at runtime within JVM that uses agent and does not affect classes on disk. If task "coverage" is not used to start server, then it starts without agent and hence classes running inside this JVM are not instrumented and their coverage is not recorded. So yes - if you want to measure coverage of classes that are executed in your server, then you must start server with agent. As written in documentation at http://www.jacoco.org/jacoco/trunk/doc/ant.html : if you can't use task "coverage" to launch your application, then alternatively you can use task "agent" that will define Ant property containing agent configuration that can be passed as parameter for "java" to start your server, or you can configure such "java" parameter manually without Ant at all. On Tuesday, September 26, 2017 at 9:27:47 AM UTC+2, Kanu Kalra wrote: > > hi evgeny, > > i have used Ant coverage tasks and it works perfectly fine for unit tests > running in the same jvm as server. jacoco.exec file is created. > > But when tests run outside the server jvm, then no jacoco-it.exec file > gets generated. It is the same instrumented code with ant coverage tasks. > Any idea why? > > Do I explicitely need to start the java agent for jacoco in server vm in > addition to specifying ant coverage task? > > Thanks > Kanu > > On Sep 4, 2017 2:35 PM, "Evgeny Mandrikov" <[email protected]> wrote: > >> >> >> On Thursday, August 31, 2017 at 6:24:56 AM UTC+2, >> [email protected] wrote: >>> >>> On Wednesday, August 30, 2017 at 9:19:48 PM UTC-7, [email protected] >>> wrote: >>> > Evgeny, >>> > >>> > Thanks. After going through docs, I have few more questions - >>> > >>> > 1. Since I use ANT file and have included <jacoco:coverage> tags >>> around the executions, my understanding is that I don't need a separate >>> java agent to run. Am I correct? >>> >> >> "coverage" task configures nested tasks to enable use of agent. >> >> >>> > >>> > 2. In the examples I see, I notice that sometime I see >>> <jacoco:coverage> tags around the execution which needs to be instrumented >>> (e.g. the server code that will be executed by tests) and sometimes I see >>> these tags around the test execution (e.g. tests which run against server >>> code). Not sure which is the correct approach? >>> >> >> Agent should always be attached to the JVM that executes application >> whose coverage should be measured. >> >> >>> > >>> > Thanks, >>> > Kanu >>> >>> -- 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]. To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/62078922-5c6e-4394-b8e1-209ff80dc461%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
