我已经配置了 maven-surefire-plugin 和 jacoco 插件来生成 junit 代码覆盖率报告。但是,我在 2 个不同的场景中遇到了 2 个不同的错误。你能看看下面的错误并帮助我吗?任何帮助都是非常可观的。
当我在 maven-surefire-plugin 配置中将 forkCount 保持为 0(零)时,所有测试都会成功执行,但不会生成 jacoco 报告。它给我的消息是“由于缺少执行数据文件而跳过 JaCoCo 执行”。
当我在 maven-surefire-plugin 配置中将 forkCount 保持为 1 时,我收到以下错误,[错误] 分叉的虚拟机在没有正确说再见的情况下终止。VM 崩溃或 System.exit 调用?[ERROR] 启动 fork 时发生错误,检查日志中的输出 [ERROR] Process Exit Code: 1 [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:671) [ERROR]在 org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:533) [错误] 在 org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:278) [错误] 在 org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:244) [错误] 在 org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1194) [错误] 在 org.apache.maven.plugin.surefire.AbstractSurefireMojo。
如果需要,您可以参考以下 pom.xml 文件以了解问题的原因,
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.testmodule test-module 1.0.6 测试模块
<properties>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<tomcat.version>8.5.4</tomcat.version>
<maven.test.skip>false</maven.test.skip>
<maven.build.timestamp.format>yy.MM</maven.build.timestamp.format>
<powermock.version>2.0.0-beta.5</powermock.version>
<!-- Sonar-JaCoCo properties -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath> …Run Code Online (Sandbox Code Playgroud) 我想以某种方式使用 Jacoco,以便它Sample.java class从整体覆盖范围中排除 a 。为了实现这个目标我已经包括<exclude>内prepare-agentMaven中pom.xml的目标
Jacoco 插件:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
万能插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<excludes>
<exclude>**/*Sample.java</exclude>
</excludes>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
属性部分:
<properties>
<argLine>-Dfile.encoding=ISO-8859-1</argLine>
</properties>
Run Code Online (Sandbox Code Playgroud) 我使用Bamboo,SonarQube和Maven插件在SonarQube中生成Jacoco报告.它正在生成jacoco.exec文件,但如何在SonarQube中显示报告?以下插件我正在使用'
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<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}/jacoco.exec</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 …Run Code Online (Sandbox Code Playgroud) 我有一个maven项目(链接),我想在其上运行代码覆盖.
我mvn test -Pcoverage jacoco:prepare-agent jacoco:report在主项目pom文件上运行命令,但不生成报告.相反,我得到一个警告说
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (post-test) @ pulsar-discovery-service ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default-cli) @ pulsar-discovery-service ---
[INFO] argLine set to -javaagent:/home/jai1/.m2/repository/org/jacoco/org.jacoco.agent/0.7.7.201606060606/org.jacoco.agent-0.7.7.201606060606-runtime.jar=destfile=/home/jai1/pulsar/pulsar-discovery-service/target/jacoco.exec
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.7.201606060606:report (default-cli) @ pulsar-discovery-service ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
Run Code Online (Sandbox Code Playgroud)
有人可以建议如何使用此pom文件生成代码覆盖率报告.我正在使用apache-maven-3.3.9和testNG.
我已经为此工作了几个小时,我在网上找到的每一个我尝试过的解决方案都没有任何区别。
我有一个用 Kotlin 编写的项目。我的声纳服务器上安装了 Kotlin 插件。我正在使用 JaCoCo 插件为声纳生成代码覆盖率报告。
我的项目是多模块的,但只有 1 个子模块有单元测试,所以我在那里定义了我的 JaCoCo 插件。
我也在使用 Surefire 插件。
这是我在 pom.xml 中的属性
<properties>
<sonar.java.binaries>target/classes</sonar.java.binaries>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>kotlin</sonar.language>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<sonar.verbose>true</sonar.verbose>
<sonar.jacoco.reportsPath>target</sonar.jacoco.reportsPath>
<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
<sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
<surefireArgLine/>
</properties>
Run Code Online (Sandbox Code Playgroud)
这是我的万无一失的插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这是我的 JaCoCo 插件:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal> …Run Code Online (Sandbox Code Playgroud) maven maven-surefire-plugin jacoco sonarqube jacoco-maven-plugin
我的整体覆盖率达到阈值,但仍将构建标记为不稳定。有谁知道这是什么原因?
16:53:04 [JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=75, maxClass=99, minMethod=75, maxMethod=99, minLine=75, maxLine=99, minBranch=40, maxBranch=99, minInstruction=65, maxInstruction=99, minComplexity=0, maxComplexity=99]
16:53:04 [JaCoCo plugin] Publishing the results..
16:53:04 [JaCoCo plugin] Loading packages..
16:53:04 [JaCoCo plugin] Done.
16:53:04 [JaCoCo plugin] Overall coverage: class: 89, method: 89, line: 77, branch: 41, instruction: 67
16:53:04 [JaCoCo plugin] Health thresholds: JacocoHealthReportThresholds [minClass=75, maxClass=99, minMethod=75, maxMethod=99, minLine=75, maxLine=99, minBranch=40, maxBranch=99, minInstruction=65, maxInstruction=99, minComplexity=0, maxComplexity=99]
16:53:04 [JaCoCo plugin] Apply Min/Max thresholds result: UNSTABLE
Run Code Online (Sandbox Code Playgroud)
jenkins jacoco jenkins-plugins jacoco-maven-plugin jenkins-pipeline
我正在尝试为我的项目创建一份 jacoco 报告。该项目是java 12版本,jacoco-maven-plugin是0.8.5版本。
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我启动了一个 mvn clean 站点
mvn clean install site
Run Code Online (Sandbox Code Playgroud)
我得到:
[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (pre-unit-test) @ bowling-game ---
[INFO] argLine set to -javaagent:/home/baptiste/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/home/baptiste/IdeaProjects/Bowling-Game/target/jacoco.exec
...
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ bowling-game ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.keywer.kata.bowling.game.frame.state.FrameStateTest
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: …Run Code Online (Sandbox Code Playgroud) 在父 POM 中,我们设置了 Jacoco 规则来强制执行测试覆盖率。这包括通常没有行为的类的一些排除:
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<excludes>
<!-- exclude largely auto-generated domain and model classes -->
<exclude>**/model/*.class</exclude>
<exclude>**/model/**/*.class</exclude>
<exclude>**/domain/*.class</exclude>
<exclude>**/domain/**/*.class</exclude>
<exclude>**/dto/*.class</exclude>
<exclude>**/dto/**/*.class</exclude>
</excludes>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.70</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
Run Code Online (Sandbox Code Playgroud)
在使用此父项的子 POM 中,添加额外的排除类模式的 Maven 魔力是什么?
我尝试combine...以各种方式使用属性,但无法正确输出有效的 POM。
有任何想法吗?
我有一个多模块 Maven 项目。这是由 jaxb 使用 xsd 生成的一组类。下面给出了此类的示例。(没有 getter 和 setter)
@XmlRootElement(name = "IPPAMUser")
public class IPPAMUser {
@XmlElement(name = "UserName", required = true)
protected String userName;
@XmlElement(name = "PAMInstanceID", required = true)
protected String pamInstanceID;
@XmlElement(name = "Product", required = true)
protected String product;
@XmlElement(name = "Password", required = true)
protected String password;
@XmlElement(name = "PasswordAlogo", required = true)
protected String passwordAlogo;
@XmlElement(name = "LastUpdatedOn", required = true)
protected String lastUpdatedOn;
@XmlElement(name = "IsGenerated")
protected boolean isGenerated;
@XmlElement(name = "LastNotifiedOn", …Run Code Online (Sandbox Code Playgroud) java reflection maven maven-surefire-plugin jacoco-maven-plugin
我有一个maven项目,我想jacoco用于代码覆盖.这是我的pom的相关部分
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<execution>
<id>pre-my-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${project.build.directory}/jacoco-it.exec</destFile>
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-my-test</id>
<phase>post-my-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
所以我能够很好地运行我的测试,并且还可以很好地构建项目.然后我跑了
mvn clean verify org.jacoco:jacoco-maven-plugin:prepare-agent
Run Code Online (Sandbox Code Playgroud)
我不断收到错误
ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.5.201505241946:
report (post-my-test) on project my-project:
An error has occurred in JaCoCo Test report generation.
Error while creating report:
Error while analyzing class /path/tp/my/project/target/classes/META-INF/
bundled-dependencies/some-third-party-1-jar-with-dependencies.jar@org/slf4j/event/
EventConstants.class. Can't add different class with same name:
org/slf4j/event/EventConstants -> [Help …Run Code Online (Sandbox Code Playgroud)