2

I'm using maven and jacoco-maven-plugin for test coverage reports

I need to configure the jacoco-agent to be on a remote machine (Linux), on which I'm running script that runs the integration tests

How do I make it?

Here's what I tried:

                    <execution>
                        <id>prepare-agent-integration</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent-integration</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.itReportPath}</destFile>
                            <jacoco.address>172.X.X.X</jacoco.address><!-- This is the machine where integration tests runs-->
                            <jacoco.port>22</jacoco.port>
                        </configuration>
                    </execution>

                    <execution>
                        <id>report-integration</id>
                        <goals>
                            <goal>report-integration</goal>
                        </goals>
                        <configuration>
                            <dataFile>${sonar.jacoco.itReportPath}</dataFile>
                            <outputDirectory>${project.basedir}/target/site/jacoco-it</outputDirectory>
                        </configuration>
                    </execution>
2
  • can you post what you have done please. I assume that you need the configuration of pom.xml? or do you need something else? Commented Oct 8, 2014 at 11:06
  • Yes this is what I need actually, I added my code.. Hope it helps Commented Oct 12, 2014 at 6:28

1 Answer 1

6

This is how the plugin is configured to see the results in a Sonar, the surefire plugin and the failsafe plugin are used in combination too. Maybe this configuration could help you.

http://maven.apache.org/surefire/maven-surefire-plugin/

http://maven.apache.org/surefire/maven-failsafe-plugin/

Properties

        <sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.jacoco.outReportPath>target/jacoco</sonar.jacoco.outReportPath>
        <sonar.jacoco.itReportPath>target/jacoco-it.exec</sonar.jacoco.itReportPath>
        <sonar.jacoco.outItReportPath>target/jacoco-it</sonar.jacoco.outItReportPath>
        <!-- Only unit tests are run by default. -->
        <skip.integration.tests>true</skip.integration.tests>
        <skip.unit.tests>false</skip.unit.tests>

maven-surefire-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>**/*IntegrationTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>

maven-failsafe-plugin

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.15</version>
                <executions>
                    <!-- Ensures that both integration-test and verify goals of the Failsafe Maven plugin are executed. -->
                    <execution>
                        <id>integration-tests</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the VM argument line used when integration tests are run. -->
                            <argLine>${failsafeArgLine}</argLine>
                            <!-- Skips integration tests if the value of skip.integration.tests property is true -->
                            <skipTests>${skip.integration.tests}</skipTests>
                            <includes>
                                <include>**/*IntegrationTest.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

jacoco-maven-plugin

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.0.201403182114 </version>
                <executions>
                    <!-- Prepares the property pointing to the JaCoCo runtime agent which is passed as VM argument when Maven the Surefire plugin is executed. -->
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                            <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>
                    <!-- Ensures that the code coverage report for unit tests is created after unit tests have been run. -->
                    <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>${sonar.jacoco.reportPath}</dataFile>
                            <!-- Sets the output directory for the code coverage report. -->
                            <outputDirectory>${sonar.jacoco.outReportPath}</outputDirectory>
                        </configuration>
                    </execution>
                    <!-- Prepares the property pointing to the JaCoCo runtime agent which is passed as VM argument when Maven the Failsafe plugin is executed. -->
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <destFile>${sonar.jacoco.itReportPath}</destFile>
                            <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
                            <propertyName>failsafeArgLine</propertyName>
                        </configuration>
                    </execution>
                    <!-- Ensures that the code coverage report for integration tests after integration tests have been run. -->
                    <execution>
                        <id>post-integration-test</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <dataFile>${sonar.jacoco.itReportPath}</dataFile>
                            <!-- Sets the output directory for the code coverage report. -->
                            <outputDirectory>${sonar.jacoco.outItReportPath}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but I still didn't get how the connection between jacoco & failsafe & integration tests script is done. My integration tests runs through a script on a remote machine, where do I specify the machine's IP and script name? or shouldn't I?
@Iker Aguayo Would you mind to post this answer in documentations? It would be a huge help for everyone (including me) who wants to setup maven/jacoco/sonar with unit and integration tests!
@Phe0nix feel free to post my answer in documentations by yourself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.