2

I want to do offline instrumentation to get coverage for my project because without that, for the server managed things (EJB's) it is showing coverage as 0%. Does anyone know how can we do offline instrumentation with gradle?

EDIT: I'm using Wildfly 8.2 application server

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Tomin
  • 1,898
  • 3
  • 18
  • 23
  • Are you talking about coverage as in test coverage? – Magnilex Apr 27 '15 at 17:28
  • yes. during testing, some components are deployed in Wildfly and the server will modify the classes in runtime. so we 'll not get the coverage for it – Tomin Apr 28 '15 at 05:55

1 Answers1

0

I don't use JaCoCo, but I've used Cobertura. As far as I know, the main superficial difference between them is that JaCoCo does runtime instrumentation, and Cobertura does compile-time instrumentation. If have no idea whether your issue with JaCoCo is fixable, but if you need to do offline or compile-time instrumentation, then you should use Cobertura.

Processing with Cobertura is as as easy as this:

plugins {
    id 'net.saliman.cobertura' version '2.2.5'
}

apply plugin: 'java'

test {
    filter {
        includeTestsMatching "*Test"
    }
}

test.dependsOn coberturaCheck

cobertura {
    coverageCheckBranchRate         = 0
    coverageCheckLineRate           = 0
    coverageCheckPackageBranchRate  = 0
    coverageCheckPackageLineRate    = 0
    coverageCheckTotalBranchRate    = 0
    coverageCheckTotalLineRate      = 0
}
David M. Karr
  • 14,317
  • 20
  • 94
  • 199
  • Thanks for the reply. Will this cure the zero coverage for EJBs and components that uses wilfly server?. Thats the main issue with jacoco that I'm facing. – Tomin Apr 28 '15 at 05:04
  • I did as per your suggestion. Now I have instrumented_classes directory in build folder which contains the instrumented classes. But the code coverage is still shows 0 % for EJB's (session beans and some resources deployed during testing in the AS ). As per the theory, we should use the instrumented classes for testing right?. But by default it is taking classes from build/classes directory for testing. Is that the reason for wrong coverage? – Tomin Apr 28 '15 at 17:49
  • Yes, you have to order your classpath so that the instrumented classes are reached before the uninstrumented classes. – David M. Karr Apr 28 '15 at 17:54
  • Would you please help me on that?. How can we order classpath accordingly in gradle? – Tomin Apr 28 '15 at 18:12
  • What you should do first is add "--debug" to your command line. That will emit a ton of output, but it will eventually show the exact "java" command line used to execute the test, including the classpath. That should provide a clue. – David M. Karr Apr 28 '15 at 18:15
  • Thanks, I think I can figure it out. There is one more issue. There are lots of test cases are failing due to an error which I don't have any clue about. I will add the stacktrace in the main question. If you have any clue, please share. – Tomin Apr 28 '15 at 18:27
  • You have FAILING test cases? That was probably an important thing to mention. It's possible it's not even finishing the coverage data processing if there are failing tests. – David M. Karr Apr 28 '15 at 18:29
  • I think so. Please check the stack trace – Tomin Apr 28 '15 at 18:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76481/discussion-between-david-m-karr-and-tomin). – David M. Karr Apr 28 '15 at 19:07