0
votes

I am trying to set-up code coverage for my project. I am using Wildfly 8.2 server, gradle as a build tool, and JUnit and Arquillian for testing. In gradle I have configured jacoco plugin to generate code coverage. I have a task called jacocoTestReport which allows me to generate an html report.

Something about running the tests: I am working on a multi module project, each sub-project has a Deployments class in which we have two methods - one for creating a shrinkwrap archive of REST classes and other for non-REST classes. In arqullian.xml we are configuring this as REST_CONTAINER and NON_REST_CONTAINER and giving path to WildFly installation directory. When we run gradle build test , It will run the whole tests by deploying the REST.ear and non-REST.ear and generate the coverage reports.

The issue is code coverage for EJB's and other server managed classes are showing 0% (From primary ananlysis of coverage report). Also I analysed the jacoco.exec, there I found the classes which are showing 0% coverage are not listed in the file (Mostly bean classes).

Can someone provide me the correct configuration which works for the combination: Wildfly-Arquillian-Gradle-Jacoco

Note: I am ok to use tools other than jacoco, tried cobertura but same result.

1
Hey, is code coverage for EJB's really impossible or something like that? It seems like no one has ever tried. - Tomin
I get code coverage just fine for my EJBs. But I don't use Arquillian, which I guess is the root of the problem, as it causes tested classes to get reloaded on a custom class loader. The code coverage tool doesn't see the reloaded class (which is the one actually getting exercised), so you get 0% coverage. - Rogério

1 Answers

0
votes

This worked for me (but I used jboss7 should not be a problem) source:https://developer.jboss.org/thread/241883


 apply plugin: 'jacoco'  
jacoco {     
    toolVersion = '0.7.4.201502262128'  
    reportsDir = file("$buildDir/jacoco")  
}  

dependencies {  
testCompile 'YOUR_ARQUILLIAN_ADAPTER'  
 testCompile 'org.jboss.arquillian.junit:arquillian-junit-container:1.1.5.Final'
  testCompile 'org.jboss.arquillian.extension:arquillian-jacoco:1.0.0.Alpha7' 
}

// Important: add the Jacoco libs on the test classpath (required for the Jacoco Arquillian extension to work). 
sourceSets {  
     test.runtimeClasspath += configurations.jacocoAnt 

}