我在互联网上搜索过这个.有很多半的答案在那里,做Maven的属性,如${sonar.jacoco.reportPath},或org.jacoco:jacoco-maven-plugin:prepare-agent或设置maven-surefire-plugin argLine带-javaagent.
一些如何,这些答案,无论是单独的还是组合的,都没有产生我正在追求的东西:一个覆盖率报告,如果它被用于堆栈中更高的测试,例如正在使用的实体,则显示一个类被覆盖通过DAO,即使它没有完全涵盖在自己的模块中的测试.
有没有确定的配置,为了达到这个目的,请?
我正在使用Maven 3.0.3,JUnit 4.8.1和Jacoco 0.6.3.201306030806,我正在尝试创建测试覆盖率报告.
我有一个只有单元测试的项目,但我无法运行报告,我反复收到错误:Skipping JaCoCo execution due to missing execution data file当我运行时:
mvn clean install -P test-coverage
Run Code Online (Sandbox Code Playgroud)
这是我的pom配置方式:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx2048m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
...
<profile>
<id>test-coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<configuration>
<destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile>
<datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile>
</configuration>
<executions>
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>prepare-integration-tests</id>
<goals> …Run Code Online (Sandbox Code Playgroud) 我有一个jacoco项目,我希望能够过滤某些类和/或包.
我已阅读以下文档:
官方jacoco网站: http ://www.eclemma.org/jacoco/index.html
关于gradle的官方jacoco文档: https ://gradle.org/docs/current/userguide/jacoco_plugin.html
官方jacoco Github问题,致力于报道:
https
://github.com/jacoco/jacoco/wiki/FilteringOptions https://github.com/jacoco/jacoco/issues/14
JaCoCo&Gradle - 过滤选项(无答案)
使用Sonarrunner和Gradle(不使用声纳)从Jacoco报告中排除软件包
JaCoCo - 从报告中排除JSP(它似乎适用于maven,我使用gradle)
Maven Jacoco配置 - 从报告中排除类/包不工作(它似乎适用于maven,我使用gradle)
JaCoCo gradle插件排除(无法使其工作)
Gradle Jacoco - 覆盖率报告包括配置中排除的类(似乎非常接近,它使用doFirst,对我不起作用)
apply plugin: 'java'
apply plugin: 'jacoco'
buildscript {
repositories {
mavenCentral()
jcenter()
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个maven多模块项目,我正在使用jacoco-maven进行代码覆盖率报告.不应该报告某些类,因为它们是Spring配置,我对它们不感兴趣.
我已经宣布了maven-jacoco插件如下:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
<exclude>some.package.*</exclude>
<exclude>**/*Config.*</exclude>
<exclude>**/*Dev.*</exclude>
<exclude>some/package/SomeClass.java</exclude>
</configuration>
<executions>
<execution>
<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>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题是,当我执行mvn clean verifyjacoco时,仍会报告应该已被排除的类,因为我的xml配置指出了.如何正确配置?
我正在使用SonarQube进行代码质量控制,然后突然构建,否则将无法分析和失败.
[INFO] [00:00:03.630]分析/mySuperProject/target/jacoco.exec - > java.io.IOException:不兼容的版本1007
当我使用调试开关调用maven构建时,会显示此原因
Caused by: java.io.IOException: Incompatible version 1007.
at org.jacoco.core.data.ExecutionDataReader.readHeader(ExecutionDataReader.java:127)
at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:107)
at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:87)
at org.sonar.plugins.jacoco.AbstractAnalyzer.readExecutionData(AbstractAnalyzer.java:134)
at org.sonar.plugins.jacoco.AbstractAnalyzer.analyse(AbstractAnalyzer.java:107)
Run Code Online (Sandbox Code Playgroud)
在检查jacoco ExecutionDataReader时,我发现异常被抛出
if (version != ExecutionDataWriter.FORMAT_VERSION) {
throw new IOException(format("Incompatible version %x.",Integer.valueOf(version)));
}
Run Code Online (Sandbox Code Playgroud)
从ExecutionDataWriter我发现了
/** File format version, will be incremented for each incompatible change. */
public static final char FORMAT_VERSION = 0x1007;
Run Code Online (Sandbox Code Playgroud)
这种不相容的变化是什么?它为什么会发生?任何想法如何解决这一挑战?
我有一些代码使用try资源和jacoco它只有一半覆盖.所有的源代码行都是绿色的,但我得到一个黄色的小符号告诉我8个分支中只有4个被覆盖.

我无法弄清楚所有分支是什么,以及如何编写涵盖它们的代码.扔三个可能的地方PipelineException.这些createStageList(),processItem()以及隐含的close()
createStageList()processItem()close()processItem()和抛出异常close()我想不出任何其他情况,但我仍然只有8个中有4个被覆盖.
有人可以向我解释为什么它是8中的4,并且无论如何都可以击中所有8个分支?我不熟悉decyrpting /阅读/解释字节码,但也许你是...... :)我已经看过https://github.com/jacoco/jacoco/issues/82,但它既不是也不是问题它非常引用帮助(除了注意这是由于编译器生成的块)
嗯,就在我写完这篇文章的时候,我想到了上面提到的那些案例可能没有被测试过......如果我做对了,我会发一个答案.我确信这个问题和答案在任何情况下都会对某人有所帮助.
编辑:没有,我没有找到它.抛出RuntimeExceptions(不由catch块处理)不包括任何更多分支
我正在使用带有jacoco插件的maven 来生成代码覆盖率指标.我有在配置一些困难神火由所需的Java插件的选项jacoco插件.我已经在Stack Overflow上看到了一些关于此问题的答案,但有些东西对我不起作用.
我有一个多模块项目,我的一个模块配置了surefire插件,如下所示:
foo/pom.xml:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-XX:MaxPermSize=512m</argLine>
</configuration>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
这按预期工作.
现在我想结合jacoco获取代码覆盖率的指标,所以我加了一个代码覆盖率配置文件,处理所有jacoco配置:
parent/pom.xml:
<profile>
<id>CodeCoverage</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals><goal>prepare-agent</goal></goals>
<configuration>
<propertyName>surefire.argLine</propertyName>
</configuration>
...
</execution>
<executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
Run Code Online (Sandbox Code Playgroud)
它是在这里看到的是,如果代码覆盖率指定配置文件,然后jacoco插件配置为使用surefire.argLine属性,该属性用于配置argLine为万无一失插件.
然后我更新了foo模块的pom.xml文件,以使用jacoco插件生成的属性:surefire.argLine
foo/pom.xml:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${surefire.argLine} -XX:MaxPermSize=512m</argLine> …Run Code Online (Sandbox Code Playgroud) 我从jacoco生成了一个代码覆盖率报告,它是jacoco.exec.但我不知道如何使用它......
我生成它的方式是通过命令行:
java -javaagent:/path/to/jacocoagent.jar=include=some.package.*,output=file org.junit.runner.JUnitCore some.package.ClassTest
Run Code Online (Sandbox Code Playgroud)
然后我得到了jacoco.exec报告.我只需要百分比,我只使用命令行.有没有办法将此报告转换为可读的txt文件?
谢谢大家
我已经切换到最新的JDK 7,我遇到了在emma覆盖工具打乱的字节代码上运行testng单元测试的问题.我的测试用例都没有正确运行,对于大多数测试用例我都收到了这样的错误.
java.lang.ClassFormatError: Illegal local variable table length 10 in method measurement.meter.AbstractSerialPortMeter.<init>(Lmeasurement/meter/SerialPort;)V at measurement.meter.Elc3133aTest.setUp(Elc3133aTest.java:42)
Run Code Online (Sandbox Code Playgroud)
我在这里找到了一篇文章JSR 292 Goodness Fast Code Coverage Tool Less 10k,它说"JSR 292引入了一个新的字节码指令invokedynamic,但也有几种新的常量池常量.这意味着大多数解析字节码的工具都像ASM,BCEL,findbugs或EMMA需要更新为兼容java 7."
检查了艾玛的主页,但看起来它已经很久没有更新了.
有人解决了类似的问题吗?
我也曾尝试过Cobertura.它看起来工作得更好但我得到了很多类型的例外VerifyError.
java.lang.VerifyError: Expecting a stackmap frame at branch target 85 in method measurement.meter.AbstractSerialPortMeter.close()V at offset 26
at measurement.meter.AbstractSerialPortMeterTest.setUp(AbstractSerialPortMeterTest.java:27)
Run Code Online (Sandbox Code Playgroud) 我正在收听声纳获取jacoco分析报告的问题.然而,詹金斯能够拿起报告并显示结果.我的项目是由詹金斯建造的maven构建.jacoco报告由maven生成(在pom中配置).通过使用Jenkins插件执行声纳.
这就是我在SonarQube上看到的:

这是我在詹金斯看到的项目报告.

maven插件配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Jenkins Sonar插件配置
