jacoco.exec file is almost empty
lenn.angel Nov 22, 2011 4:59 AMHi !
I'm currently developping a library that will be used by multiple EJB. So I need to test this library, we use basic Junit test for some functions but for others we need that our library is embedded in an Java EE container so we used Arquillian with jacoco.
So the Arquillian test do the following :
- deploy a basic test ejb + the library
- call a service of the ejb that use the library
Everything works fine but the generated "jacoco.exec" is almost empty. It only contains jacoco headers. If I use it with sonar it plugin 0% coverage is done.
Here my project architecture (I create a basic project to resolve this problem) :
!http://www.monsterup.com/upload/1321955504980.png!
My pom.xml :
{code:xml}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroupid</groupId>
<artifactId>arquillianTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ArquillianTest</name>
<description></description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.0.CR4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-managed-6</artifactId>
<version>1.0.0.CR2</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-server-manager</artifactId>
<version>1.0.3.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<version>1.0.0.CR4</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-jacoco</artifactId>
<version>1.0.0.Alpha1</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>0.5.4.201111111111</version>
</dependency>
</dependencies>
</project>
{code}
The Arquillian test code :
{code}
@RunWith(Arquillian.class)
public class GreetingTest {
@EJB
GreetingManager manager ;
@Deployment
public static Archive createTestArchive() throws IllegalArgumentException, FileNotFoundException, IOException {
// the archive for the EJB
Package greetingPackage = GreetingTest.class.getPackage();
JavaArchive greetingArchive = ShrinkWrap.create(JavaArchive.class, "greetingManager.jar").addPackages(true, greetingPackage);
// the archive for my library that we want to test
JavaArchive frameworkLib = ShrinkWrap.create(JavaArchive.class, "framework.jar").addPackages(true, "com/cs/framework");
// Create an ear with the EJB and the library
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class);
ear.addAsModule(greetingArchive);
ear.addAsLibraries(frameworkLib);
ear.as(ZipExporter.class).exportTo(new File("target/out.ear"), true);
return ear;
}
@Test
public void basicTest() throws Exception {
String userName = "Earthlings";
Assert.assertNotNull(manager);
Assert.assertEquals("Hello " + userName, manager.greet(userName));
}
}
{code}
The EJB implementation :
{code}
public String greet(String userName)
{
MyClassToCover ctc = new MyClassToCover();
ctc.setValue(userName.length()) ;
return "Hello " + userName;
}
{code}
After running here the content of the jacoco.exec :
!http://www.monsterup.com/upload/1321955714327.png!
I tried all of this versions :
jacoco : 0.5.4.... , 0.5.3....
jboss : 5.1 & 6.0 (both in managed and remote)
arquillian-junit-container : CR2 - CR4
Some ideas ?
Thanks for the help !
Full project in joined.
-
arquillianTest.zip 38.8 KB