当前位置: 首页 > 知识库问答 >
问题:

用于远程机器上集成测试的Jacoco代理

令狐良骏
2023-03-14

我正在使用maven和jacoco maven插件来测试覆盖率报告

我需要将Jacoco代理配置为在远程机器(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个答案

魏宸
2023-03-14

这是如何配置插件以在声纳中查看结果的,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>
            <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>
 类似资料:
  • 我试图找到这个答案,但几乎找不到。我正在进行API测试,在此过程中,我需要从本地计算机调用其余的API。本地机器包含maven项目和调用相应rest API的框架。 我需要检查远程Rest API的代码覆盖率,并根据代码覆盖率形成报告。请帮忙,怎么做? 注意:我发现这个链接很有用,但是它没有详细说明该怎么做? http://eclemma.org/jacoco/trunk/doc/agent.ht

  • 对于集成测试,它更棘手,我们使用failsafe和集成测试生成文件,该文件由Sonar扫描。我的问题是,集成测试位于中,它只显示了对控制器内部的类的集成测试的测试覆盖范围,而不显示对另一个模块(如service module)中的类的集成测试的测试覆盖范围。因此,集成测试的总体测试覆盖率增加到21%,而不是35%+。 如果集成测试在中,那么是否可以配置sonar和jacoco来测量所有类的集成测试

  • 我想在android项目中生成JUnit测试的代码覆盖率报告,所以我添加了JaCoCo gradle插件。这是我的项目级文件: 它通过运行<code>工作得很好/gradlew JacoFullReport。但不幸的是,使用<code>RobolectricTestRunner@RunWith注释的测试,或者使用运行的测试报告覆盖率很好。 任何帮助都将不胜感激来解决这个问题。 更新1:我注意到我应

  • 我试图从jacoco exec文件(在远程服务器上生成)生成jacoco代码覆盖率报告,该文件已复制到Jenkins工作区。 我的要求是在远程位置启动服务器,然后对远程服务器执行场景测试,并获得代码覆盖率。 为此,我将jacoco代理放在服务器端,然后将jacoco代理作为JVM选项连接,并在服务器端执行检测。这将在服务器启动时在服务器端自动生成一个空的jacoco exec文件。然后我执行测试并

  • 我正在使用arquillian和tomee远程插件进行集成测试。它工作得很好。但我的代码覆盖率不起作用。我使用Jacoco插件来覆盖代码。在我的Java类Java中遇到异常。朗,乐器。IllegalClassFormatException:检测com/demo/EmpService时出错 如何使用Jacoco在远程容器中进行代码覆盖? 注意:我已经在集成阶段将javaagent(argLine)传

  • 使用jacoco代理并获取测试覆盖率报告有大量答案。大多数答案都是一半,我有点困惑。 以下是我想做的:1。我的Java应用程序正在某个远程服务器上运行。说IP-192.168.17.7 我使用以下命令运行测试:mvn-Denv=stage-Dmaven。测验失败ignore=true-DsuiteFile=src/test/java/Smoke。xml测试 现在我如何通过使用Jacoco代理获得J