cobertura-maven-plugin icon indicating copy to clipboard operation
cobertura-maven-plugin copied to clipboard

Arquillian and Cobertura: 0% percent coverage or ClassNotFoundException

Open gerrit-hohl opened this issue 8 years ago • 4 comments

Hello everyone, 😄

I have a working Arquillian based WildFly test within a Maven build. And now I want to add Cobertura coverage tests.

But it seems it isn't easy: If I just include Cobertura through the Cobertura Maven plugin my build fails because every class has a coverage of 0%, the tests are marked as "Error" (only during the Cobertura test execution, the normal test execution works without any problems) and I get the following error in the console:

java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/TouchCollector
Caused by: java.lang.ClassNotFoundException: net.sourceforge.cobertura.coveragedata.TouchCollector from [Module "deployment.91f93bde-a5de-4cd1-a8e4-d1174885713f.war:main" from Service Module Loader]

And if I add the Cobertura library to the deployment, I get the following error at the end of the complete testing:

Exception in thread "Thread-94" java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/ClassData
    at net.sourceforge.cobertura.coveragedata.ProjectData.getOrCreateClassData(ProjectData.java:88)
    at net.sourceforge.cobertura.coveragedata.TouchCollector.applyTouchesOnProjectData(TouchCollector.java:109)
    at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:272)
    at net.sourceforge.cobertura.coveragedata.SaveTimer.run(SaveTimer.java:33)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: net.sourceforge.cobertura.coveragedata.ClassData from [Module "deployment.10d71cf1-6f23-46b2-9295-dd93eb249f3f.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
    ... 5 more

Then I get a coverage rate. But it is very ugly and the next colleague stumbling across this message will try to fix it.

Is there a way to fix that problem? I guess it's about the different class loaders and that the inner Cobertura library tries to communicate with the outer Cobertura library. But I have no clue how to solve something like that.

P.S.: I posted a similar request as a thread in the Arquillian forum. I also opened an issue in the Cobertura project.

gerrit-hohl avatar Dec 19 '16 07:12 gerrit-hohl

What version of Cobertura and Arquillian are you using.

Jroosterman avatar Dec 22 '16 13:12 Jroosterman

Hi everyone,

I have exactly the same issue with the version 2.7 of the maven plugin, on Java 8/Jenkins environment.

Do you have any idea why this issue happens ?

Thank you.

mamghari avatar Jan 02 '17 09:01 mamghari

I found a workaround that could be integrated into the maven plugin, I think the asm dependency should be updgraded to 5.1 in the next release.

In my pom.xml file I changed the asm version dependency from the plugin management section like following:

				<plugin>
					<groupId>org.codehaus.mojo</groupId>
					<artifactId>cobertura-maven-plugin</artifactId>
					<version>${cobertura.version}</version>
					<dependencies>  
		                                <dependency>  
		                                          <groupId>org.ow2.asm</groupId>  
		                                         <artifactId>asm</artifactId>  
		                                         <version>5.1</version>  
		                                </dependency>  
	            	                </dependencies>  
					<configuration>
						......
					</configuration>
					<executions>
						.....
					</executions>
				</plugin>

inpsired from http://www.befreeman.com/2014/09/getting-cobertura-code-coverage-with.html

mamghari avatar Jan 02 '17 15:01 mamghari

I'm having the same problem. I've made the "asm" plugin workaround (version 5.1) and cobertura plugin (version 2.7) doesn't recognize Arquillian tests. I get the following error: "failed coverage check. Branch coverage rate of 0.0% is below 75.0%", in all my test classes.

mmarquezvacas avatar Jun 21 '17 21:06 mmarquezvacas