Hello Friends ,
In last day i was doing some configuration work to extract functional coverage report using JACOCO Agent.jar. At first i would mention that i was working on maven project and it was running over the Apache Spark 1.5 .
I followed steps mentioned below to get functional coverage (You can comment below if you have any better way to do this 🙂 ).
1. Download jacoco-agent.jar
2. Extract the jar and you’ll find a jacoco-agent.jar inside the extracted folder.
3.Configure spark-default.conf with your project(as most probably you had configured in start of your project) and jacoco-agent.
spark.executor.extraJavaOptions
-Dproject.properties.filepath=/your/project.properties/path
-javaagent:/your/path/jacocoagent.jar=destfile=/tmp/jacoco/jacoco.exec=output=
filespark.driver.extraJavaOptions
-Dproject.properties.filepath=/your/project.properties/path
-javaagent:/your/path/jacocoagent.jar=destfile=/tmp/jacoco/jacoco.exec=output=
file
4. Run the spark-submit command.
5. Execute your functionality(or Querry).
6. Now stop the spark-submit command.
7. jacoco.exec would be placed at the destfile path(/tmp/jacoco).If already yo have generated your jacoco.exec from any other way you can follow step 8 & 9 to generate report in HTML format.
8. Add following plugin to pom.xml in your project :
<!– Jococo–>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!– Sets the path to the file which contains the execution data. –>
<dataFile>tmp/jacoco/jacoco.exec</dataFile>
<!– Sets the output directory for the code coverage report. –>
<outputDirectory>${projectOutputDirectory}/jacoco-functional-test-report</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<!– Sets the VM argument line used when unit tests are run. –>
<argLine>${surefireArgLine}</argLine>
<!– Skips unit tests if the value of skip.unit.tests property is true –>
<skipTests>${skip.unit.tests}</skipTests>
<!– Excludes integration tests when unit tests are run. –>
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
</configuration>
</plugin>
<!– Jococo–>
- Run mvn test from from your project.Coverage report in html format generated at specified location as given in maven plugin.
Thanks.