2

我正在使用 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>
4

1 回答 1

6

这就是配置插件以在 Sonar 中查看结果的方式,surefire 插件和 failsafe 插件也可以组合使用。也许这个配置可以帮助你。

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>

maven-surefire-插件

            <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>
                <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>
                <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>
于 2014-10-13T07:10:18.173 回答