Discussion:
Configuring jacoco for OSGI (Karaf)
Bhupendra Mahajan
2014-03-21 09:27:39 UTC
Permalink
Hi All,

After struggling a lot I was able to generate the reports for my
Application Under Test (AUT)

May be helpful to someone, so just listing down the steps that I followed

1. Download the Jacoco package http://www.eclemma.org/jacoco/
2. Extract the jar to some folder in your local machine
viz. <JACOCO_HOME>
3. Create folder <Path_TO_JACOCO>/reports
4. Create folder <Path_TO_JACOCO>/reports/jacococlasses
5. In karaf.bat put following
1. *set JACOCO_HOME=<Path_TO_JACOCO>/Jacoco*
2. set DEFAULT_JAVA_OPTS=-server -Xms%JAVA_MIN_MEM%
-Xmx%JAVA_MAX_MEM% -Dderby.system.home="%KARAF_DATA%\derby"
-Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote
*-javaagent:%JACOCO_HOME%/lib/jacocoagent.jar=destfile=%JACOCO_HOME%/reports/jacoco.exec,append=true,includes=com.<yourCompany>.*,dumponexit=true,output=file,classdumpdir=%JACOCO_HOME%/reports/jacococlasses*
6. Start karaf
7. Execute the tests that you want to perform on AUT
8. Shutdown the karaf elegantly (I use Ctrl + D)
9. See that jacoco.exec is now populated
and <JACOCO_HOME>/reports/jacococlasses
10. Download eclipse (I used Kepler)
11. Install maven plugin
12. Create a project jacoco-maven-plugin
13. Create a POM file with content given below
14. Run maven project (RClick on project -> Run As -> Maven Clean)
15. Run maven project (RClick on project -> Run As -> Maven Install)
16. Now copy the classes (*com *folder) from
<JACOCO_HOME>/reports/jacococlasses to <eclipse_project_root>/target/classes
17. Copy jacoco.exec from <JACOCO_HOME>/reports/ to
<eclipse_project_root>/target
18. Now from eclipse run the plugin (RClick on project -> Run As -> Run
Configurations)
19. In goals put "org.jacoco:jacoco-maven-plugin:report"
20. Click on Run
21. On successful run a new folder <eclipse_project_root>/site/jacoco
will be created
22. The code coverage report can be opened
from <eclipse_project_root>/site/jacoco/index.html

pom.xml >>>

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.5.201403032054</version>
</plugin>
</plugins>
</reporting>
</project>
--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
c***@public.gmane.org
2014-04-25 09:36:23 UTC
Permalink
Post by Bhupendra Mahajan
Hi All,
After struggling a lot I was able to generate the reports for my Application Under Test (AUT)
May be helpful to someone, so just listing down the steps that I followed
Download the Jacoco package http://www.eclemma.org/jacoco/
Extract the jar to some folder in your local machine viz. <JACOCO_HOME>Create folder <Path_TO_JACOCO>/reportsCreate folder <Path_TO_JACOCO>/reports/jacococlassesIn karaf.bat put following 
set JACOCO_HOME=<Path_TO_JACOCO>/Jacocoset DEFAULT_JAVA_OPTS=-server -Xms%JAVA_MIN_MEM% -Xmx%JAVA_MAX_MEM% -Dderby.system.home="%KARAF_DATA%\derby" -Dderby.storage.fileSyncTransactionLog=true -Dcom.sun.management.jmxremote -javaagent:%JACOCO_HOME%/lib/jacocoagent.jar=destfile=%JACOCO_HOME%/reports/jacoco.exec,append=true,includes=com.<yourCompany>.*,dumponexit=true,output=file,classdumpdir=%JACOCO_HOME%/reports/jacococlasses
Start karafExecute the tests that you want to perform on AUTShutdown the karaf elegantly (I use Ctrl + D)See that jacoco.exec is now populated and <JACOCO_HOME>/reports/jacococlasses
Download eclipse (I used Kepler)Install maven pluginCreate a project jacoco-maven-pluginCreate a POM file with content given belowRun maven project (RClick on project -> Run As -> Maven Clean)Run maven project (RClick on project -> Run As -> Maven Install)
Now copy the classes (com folder) from <JACOCO_HOME>/reports/jacococlasses to <eclipse_project_root>/target/classesCopy jacoco.exec from <JACOCO_HOME>/reports/ to <eclipse_project_root>/targetNow from eclipse run the plugin (RClick on project -> Run As -> Run Configurations)In goals put "org.jacoco:jacoco-maven-plugin:report"Click on RunOn successful run a new folder <eclipse_project_root>/site/jacoco will be createdThe code coverage report can be opened from <eclipse_project_root>/site/jacoco/index.html
pom.xml >>>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.6.5.201403032054</version>
      </plugin>
    </plugins>
  </reporting>
</project> 
Hi,

It works too with Pax-exam, jacoco-maven and failsafe, without having to tweak karaf instance:

You just have to pass the jacoco.argline as a failsafe systemVariable, then register a paxExam vmOption corresponding to the variable previously registered.

See here for the Exam vm Option: https://github.com/OsgiliathEnterprise/net.osgiliath.parent/blob/master/net.osgiliath.framework/net.osgiliath.features.karaf-features/net.osgiliath.features.karaf-features.itests/net.osgiliath.features.karaf-features.itests.cdi/src/it/java/helper/exam/AbstractKarafPaxExamConfiguration.java

And here for the plugins configuration (look at failsafe and jacoco): https://github.com/OsgiliathEnterprise/net.osgiliath.parent/blob/master/net.osgiliath.poms/net.osgiliath.pom.repositories/net.osgiliath.pom.reporting/net.osgiliath.pom.plugins/pom.xml

Regards,
--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Loading...