Functional Coverage with Jacoco Agent in Maven project(uses Apache Spark)


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=
file

spark.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–>

  1. Run mvn test from from your project.Coverage report in html format generated at specified location as given in maven plugin.

Thanks.

KNOLDUS-advt-sticker

About Rahul Kumar

Software Consultant At Knoldus
This entry was posted in Scala. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s