Jacoco代理在远程机器上进行集成测试

时间:2014-10-08 09:17:31

标签: maven maven-3 code-coverage jacoco jacoco-maven-plugin

我使用maven和jacoco-maven-plugin进行测试覆盖率报告

我需要将jacoco-agent配置为远程计算机(Linux),我在其上运行运行集成测试的脚本

我该如何制作?

这是我尝试的内容:

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

1 个答案:

答案 0 :(得分:5)

这是插件配置为在Sonar中查看结果的方式,surefire插件和故障安全插件也是组合使用的。也许这种配置可以帮到你。

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

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

属性

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

行家-万无一失-插件

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

行家故障安全-插件

            <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-行家-插件

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