Jacoco报告未考虑Maven中的Cucumber测试。

huangapple 未分类评论44阅读模式
英文:

Jacoco report is not considering Cucumber tests in Maven

问题

已编写了一些Cucumber测试,并使用Jacoco插件生成代码覆盖率报告。我正在使用Maven进行构建。在执行'mvn test'时,首先执行Cucumber测试,然后执行Jacoco以生成报告。但是,代码覆盖率显示测试中使用的类的覆盖率为0%。看起来Jacoco没有考虑Cucumber测试的代码覆盖率。以下是pom.xml文件的内容:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.6</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>5.5.0</version>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-core</artifactId>
    <version>5.5.0</version>
</dependency>
<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>5.5.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>5.4.1</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>3.0.0-M4</version>
        </dependency>
    </dependencies>
    <configuration>
        <testFailureIgnore>true</testFailureIgnore>
        <additionalClasspathElements>
            <additionalClasspathElement>src/test/java/</additionalClasspathElement>
        </additionalClasspathElements>
    </configuration>
</plugin>
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.5</version>
    <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <excludes>
                    <include>**/libs/*</include>
                </excludes>
                <dataFile>target/jacoco.exec</dataFile>
                <outputDirectory>target/my-reports</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

如果有人能帮助我,我将不胜感激。我认为可能是缺少Jacoco的某些配置。

英文:

Written some cucumber tests and used Jacoco plugin to generate code coverage report. I am using maven for build. While doing 'mvn test' cucumber tests are being executed after that Jacoco is being executed to generate the report. However the code coverage is showing 0% for the class which is being used in tests. It looks like the Jacoco is not considering the cucumber tests for code coverage. Below is the pom.xml.

   &lt;dependency&gt;
		&lt;groupId&gt;io.cucumber&lt;/groupId&gt;
		&lt;artifactId&gt;cucumber-jvm-deps&lt;/artifactId&gt;
		&lt;version&gt;1.0.6&lt;/version&gt;
		&lt;scope&gt;test&lt;/scope&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;io.cucumber&lt;/groupId&gt;
		&lt;artifactId&gt;cucumber-java&lt;/artifactId&gt;
		&lt;version&gt;5.5.0&lt;/version&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;io.cucumber&lt;/groupId&gt;
		&lt;artifactId&gt;cucumber-core&lt;/artifactId&gt;
		&lt;version&gt;5.5.0&lt;/version&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;io.rest-assured&lt;/groupId&gt;
		&lt;artifactId&gt;rest-assured&lt;/artifactId&gt;
		&lt;version&gt;4.3.0&lt;/version&gt;
		&lt;scope&gt;test&lt;/scope&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;io.cucumber&lt;/groupId&gt;
		&lt;artifactId&gt;cucumber-junit&lt;/artifactId&gt;
		&lt;version&gt;5.5.0&lt;/version&gt;
		&lt;scope&gt;test&lt;/scope&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;io.cucumber&lt;/groupId&gt;
		&lt;artifactId&gt;cucumber-testng&lt;/artifactId&gt;
		&lt;version&gt;5.4.1&lt;/version&gt;
		&lt;scope&gt;test&lt;/scope&gt;
		&lt;exclusions&gt;
			&lt;exclusion&gt;
				&lt;groupId&gt;junit&lt;/groupId&gt;
				&lt;artifactId&gt;junit&lt;/artifactId&gt;
			&lt;/exclusion&gt;
		&lt;/exclusions&gt;
	&lt;/dependency&gt;


    &lt;plugin&gt;
			&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
			&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
			&lt;version&gt;2.19.1&lt;/version&gt;
			&lt;dependencies&gt;
				&lt;dependency&gt;
					&lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
					&lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
					&lt;version&gt;5.6.0&lt;/version&gt;
				&lt;/dependency&gt;
				&lt;dependency&gt;
					&lt;groupId&gt;org.apache.maven.surefire&lt;/groupId&gt;
					&lt;artifactId&gt;surefire-junit47&lt;/artifactId&gt;
					&lt;version&gt;3.0.0-M4&lt;/version&gt;
				&lt;/dependency&gt;
			&lt;/dependencies&gt;
			&lt;configuration&gt;
				&lt;testFailureIgnore&gt;true&lt;/testFailureIgnore&gt;
				&lt;additionalClasspathElements&gt;
					&lt;additionalClasspathElement&gt;src/test/java/&lt;/additionalClasspathElement&gt;
				&lt;/additionalClasspathElements&gt;
			&lt;/configuration&gt;
		&lt;/plugin&gt;
        &lt;plugin&gt;
			&lt;groupId&gt;org.jacoco&lt;/groupId&gt;
			&lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
			&lt;version&gt;0.8.5&lt;/version&gt;
			&lt;executions&gt;
				&lt;execution&gt;
					&lt;id&gt;prepare-agent&lt;/id&gt;
					&lt;goals&gt;
						&lt;goal&gt;prepare-agent&lt;/goal&gt;
					&lt;/goals&gt;
				&lt;/execution&gt;
				&lt;execution&gt;
					&lt;id&gt;report&lt;/id&gt;
					&lt;phase&gt;prepare-package&lt;/phase&gt;
					&lt;goals&gt;
						&lt;goal&gt;report&lt;/goal&gt;
					&lt;/goals&gt;
				&lt;/execution&gt;
				&lt;execution&gt;
					&lt;id&gt;post-unit-test&lt;/id&gt;
					&lt;phase&gt;test&lt;/phase&gt;

					&lt;goals&gt;
						&lt;goal&gt;report&lt;/goal&gt;
					&lt;/goals&gt;
					&lt;configuration&gt;
						&lt;excludes&gt;&lt;include&gt;**/libs/*&lt;/include&gt;&lt;/excludes&gt;
						&lt;dataFile&gt;target/jacoco.exec&lt;/dataFile&gt;
						&lt;outputDirectory&gt;target/my-reports&lt;/outputDirectory&gt;
					&lt;/configuration&gt;
				&lt;/execution&gt;
			&lt;/executions&gt;

		&lt;/plugin&gt;

I would be really thankful if somebody could help me out here. I assume - missing some configuration for jacoco.

huangapple
  • 本文由 发表于 2020年4月9日 18:50:32
  • 转载请务必保留本文链接:https://java.coder-hub.com/61119446.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定