3

我正在尝试使用 maven failsafe 运行测试以显示在 jacoco 报告中,我已经拆分了单元测试和集成测试,并且我的所有测试都通过并且验证运行良好。

我在目标目录中获得了一个创建的集成测试报告,即使我使用 selenium 的基本测试确实遇到了一些控制器功能,它也始终显示零覆盖率。

如何让 jacoco 获得硒驱动测试的覆盖范围?

单元测试报告很好,向我展示了代码覆盖率,所以这仅适用于 selenium 测试,我没有遇到任何构建问题并且测试确实运行,它们似乎没有得到任何覆盖率报告。

下面是我的故障安全和 jacoco pom 文件片段,我正在运行 maven clean verify,我还在使用 cargo 插件在 tomcat 中运行我的 war 文件,我正在使用 phantom js maven 插件。

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <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>
                <systemPropertyVariables>
                    <phantomjs.binary>${phantomjs.binary}</phantomjs.binary>
                </systemPropertyVariables>
            </configuration>
            <executions>
                <execution>
                    <id>default</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

      <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.5.201505241946</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>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                        <!-- Sets the name of the property containing the settings for JaCoCo 
                            runtime agent. -->
                        <propertyName>surefireArgLine</propertyName>
                        <includes>
                            <include>com/test/**</include>
                        </includes>
                    </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>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</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>${project.build.directory}/coverage-reports/jacoco-it.exec</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>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
4

0 回答 0