3 Replies Latest reply on Nov 22, 2011 8:25 AM by Aslak Knutsen

    jacoco.exec file is almost empty

    Lenn Angel Newbie

      Hi !


      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) :




      My pom.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">





























































      The Arquillian test code :




      public class GreetingTest {



          GreetingManager manager ;



          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.as(ZipExporter.class).exportTo(new File("target/out.ear"), true);



              return ear;




          public void basicTest() throws Exception {

              String userName = "Earthlings";


              Assert.assertEquals("Hello " + userName, manager.greet(userName));





      The EJB implementation :


      public String greet(String userName)


            MyClassToCover ctc = new MyClassToCover();

            ctc.setValue(userName.length()) ;


            return "Hello " + userName;




      After running here the content of the jacoco.exec :




      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.

        • 1. Re: jacoco.exec file is almost empty
          Aslak Knutsen Master

          This could be related to how our jacoco extension store it's coverage data. I suspect the classloading in a EnterpriseArchive will cause the data to be stored in a different 'classloader'.


          Try using a WebArchive instead, see if that helps

          • 2. Re: jacoco.exec file is almost empty
            Lenn Angel Newbie

            Hi !


            First of all thanks ! Your answer helped me to correct all my problems.


            1) First I changed my EAR to a WAR :


            WebArchive war = ShrinkWrap.create(WebArchive.class);

            war.addPackages(true, greetingPackage);



            But with jacoco core I've got :


            Caused by: org.jboss.shrinkwrap.api.exporter.ArchiveExportException: java.lang.NoSuchMethodError: org.jacoco.core.instr.Instrumenter.<init>(Lorg/jacoco/core/runtime/IRuntime;)V


            2) Switch jacoco back to


            Now deployment fails because of the "@EJB" annotation :


            java.lang.RuntimeException: beanInterface specified, interface com.cs.frameworktests.integration.greeting.ejb.GreetingManager, is not unique within EJB GreetingManagerFacade


            3) Specify interface class


            changed "@EJB" to "@EJB(beanInterface=GreetingManagerRemote.class)"


            Now everything works fine and I've got some coverage data in jacoco.exec :

            - com/cs/frameworktests/integration/greeting/ejb/GreetingManagerFacade

            - com/cs/frameworktests/integration/greeting/GreetingTest


            But it seems that the classes contained in the library isn't covered correctly...


            4) Changed WAR to JAR :


            JavaArchive jar = ShrinkWrap.create(JavaArchive.class);

            jar.addPackages(true, "com/cs/framework");

            jar.addPackages(true, greetingPackage);


            Now everything works fine and I've got some coverage data in jacoco.exec :


            - com/cs/frameworktests/integration/greeting/GreetingTest

            - com/cs/frameworktests/integration/greeting/ejb/GreetingManagerFacade

            - com/cs/framework/MyClassToCover



            Success !!

            • 3. Re: jacoco.exec file is almost empty
              Aslak Knutsen Master

              Currently it's not instrumenting classes in nested Archives. Got a fix for this coming in Alpha2

              1 of 1 people found this helpful