6 Replies Latest reply on Jan 11, 2012 9:15 AM by zhfeng

    collect code coverage by using jacoco-extension

    zhfeng

      I managed to run coverage on jbossxts by using jacoco-extension. Our test cases need to run in the container, and now jacoco could only collecte the data of these test cases but not XTS codes.

       

      e.g. test case running in the container

       

      public class NestedTransaction
      {
          public void testNestedTransaction()
                  throws Exception {
               UserTransaction ut = UserTransaction.getUserTransaction();
               try {
                   ut.begin();             ut.begin();
                   ut.commit();
                   ut.commit();
                   fail("expected WrongStateException");
               } catch(...) {
                   ...
               }
           }
      }  
      

       

      deploy and test via arquillian

       

      @RunWith(Arquillian.class)
      public class NestedTransactionTest {
          @Inject
          NestedTransaction test;
      
          @Deployment
          public static WebArchive createDeployment() {
              return WarDeployment.getDeployment(NestedTransaction.class);
          }
      
          @Test
          public void test() throws Exception {
              test.testNestedTransaction();
          }
      }
      

      so my question is it possible to control the jars instrumented with jacoco ? or we need a new feather about jacoco-extension ?

       

      Thanks,

      Amos

        • 1. Re: collect code coverage by using jacoco-extension
          aslak

          The jacoco extension only instrument the classes in your @Deployment, not classes found in the runtime environment where it is deployed, e.g. UserTransaction.

           

          I'm assuming you want to see in your report that UserTransaction.begin was called ?

          • 2. Re: collect code coverage by using jacoco-extension
            zhfeng

            yeah, it's exactly what we want to see in the coverage report for UserTansaction.begin

             

            I looked into the jacoco-extension codes and found it uses ApplicationArchiveInstrumenter to instrument the classes.

            so is it possible to write my own similar ArchiveInstrumenter and register it in arquillian to instrument the jbossxts.jar which we want to collect coverage data ?

             

            Thanks,

            Amos

            • 3. Re: collect code coverage by using jacoco-extension
              aslak

              Is the jbossxts.jar in your @Deployment ?

               

              If it is, it should work currently if you only add the jar as a ShrinkWrap Archive instead of just a file reference.

              • 4. Re: collect code coverage by using jacoco-extension
                zhfeng

                No, it is not in @Deployment.

                 

                jbossxts.jar is a module of jbossas and it is in <JBOSS_HOME>/modules/org/jboss/xts/main

                any idea about this ?

                 

                Thanks,

                Amos

                • 5. Re: collect code coverage by using jacoco-extension
                  aslak

                  Right, that's what i thought.

                   

                  To do that we would have to instrument the app servers classloaders, which is something we don't crrently do. Only your defined @Deployment.

                   

                  In theory you might be able to deploy the jbosstx subsystem as part of your test, but...

                  • 6. Re: collect code coverage by using jacoco-extension
                    zhfeng

                    OK, I get it.

                     

                    to instrument the app servers classloaders, I think we could use "-javaagent:jacocoagent.jar=..." and controll the arquillian start with this jvm arguments.

                    the problem is that the jacoco.exec is output to the server side and the client can not receive this file.

                     

                    is it too difficult to do these in jacoco-extension ? I'm interest to try it out.