使用Jacoco进行黄瓜测试的代码覆盖率 [英] Code Coverage for Cucumber Tests using Jacoco

查看:90
本文介绍了使用Jacoco进行黄瓜测试的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试集成Jacoco,以使用Maven获得有关Cucumber测试的代码覆盖率.以下是我的项目结构:

I am trying to integrate Jacoco to get the code coverage for my Cucumber tests using Maven. Following is my project structure:

  • -src-main-java-Pages

  • -src-main-java-Pages

-src-main-java-Helper

-src-main-java-Helper

-src-test-java-resources-features

-src-test-java-resources-features

-src-test-java-Steps

-src-test-java-Steps

以下是我的POM.xml中的Jacoco配置

Following is the Jacoco configuration in my POM.xml

          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.2</version>
            <configuration>
                <destFile>${basedir}/target/coverage-reports/jacoco.exec</destFile>
                <dataFile>${basedir}/target/coverage-reports/jacoco.exec</dataFile>
                <outputDirectory>${basedir}/target/coverage-reports/jacoco</outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>check</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <rule>
                                <element>PACKAGE</element>
                                <includes>
                                    <include>**/*Steps.*</include>
                                </includes>
                            </rule>
                            <rule>
                                <element>PACKAGE</element>
                                <excludes>
                                    <exclude>**/*Pages.*</exclude>
                                    <exclude>**/*Page.*</exclude>
                                </excludes>
                            </rule>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我能够生成代码覆盖率报告.但是,在该报告中,它涵盖了-src-main软件包中的所有类.根据不同的google研究和SO帖子,我试图修改我的POM以排除Pages,并且在代码覆盖率报告中仅包括Steps.但是不知何故,它继续显示主包中的所有文件.

I am able to generate the code coverage report. However, in the report, it covers all the classes in the -src-main packages. As per different google researches and SO posts, I tried to modify my POM to exclude Pages and include only Steps in my code coverage report. But somehow, it keeps on displaying all the files in the main package.

我采用错误的方法吗?我只想创建一个报告,该报告仅针对我执行的测试而不是主软件包中的所有文件进行代码覆盖.

Am I taking the wrong approach? I just want to create a report which does code coverage for only the tests that I execute rather than all the files in the main package.

推荐答案

请参见

See https://maven.apache.org/guides/mini/guide-configuring-plugins.html - you specify exclusions in configuration of

<execution>
    <id>check</id>
    <goals>
        <goal>check</goal>

但没有配置

<execution>
    <id>report</id>
    <goals>
        <goal>report</goal>

因此它对check有影响,但对report没有影响.

so it has effect on check, but not on report.

这篇关于使用Jacoco进行黄瓜测试的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆