![](/img/trans.png)
[英]Generate Jacoco code coverage report for individual unit tests using gradle
[英]Unit tests coverage using Jacoco for Scala
当我在Maven项目中使用以下结构时:
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-g:line</arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.8.201207111220</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
执行了测试,但未创建jacoco.exec文件。 我试图将此标签destFile添加到prepare-agent目标,但没有成功(未创建包含coverage信息的文件)。
是否有人使用maven和Jacoco计算Scala单元测试的代码覆盖率?
Jacoco maven插件的工作取决于JDK,Scala和插件本身的版本。
只需添加相同的配置即可正常运行:jacoco.exec和带有报告的site / jacoco都位于目标目录中: https : //github.com/plokhotnyuk/calculator/commit/e3a84db02dd942b0df71d4fa337df29512e213f6
然后在使用最新(0.6.2.201302030002)版本的Jacoco maven插件时出现代理故障:
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:99)
at org.jacoco.agent.rt.internal_5d10cad.PreMain.createRuntime(PreMain.java:51)
at org.jacoco.agent.rt.internal_5d10cad.PreMain.premain(PreMain.java:43)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.lang.Class.getField(Class.java:1542)
at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:136)
... 9 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
然后通过从JDK8切换到JDK7来解决故障。 承保范围报告数字未更改。
同样,切换到Scala 2.10后,开始突出显示源代码行看起来也不同:
斯卡拉2.9
Scala 2.10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.