标签: jacoco

在 SONAR 中使用 Jacoco 的 IT 测试覆盖率为 0%

我在用:

SONAR v.3.2(它有jacoco)

Maven 3.0.4

遵循“ http://johndobie.blogspot.in/2012/05/easy-unit-and-integration-code-coverage.html#comment-form ”以获得单元和IT测试的单独代码覆盖率。但 IT 测试覆盖率显示为 0%。它生成单独的 jacoco-unit.exec (44kb) 和 jacoco-it.exec (14kb),但覆盖率仅显示在 SONAR 上的单元测试中。

日志显示为:

[INFO] [13:10:23.515] Sensor SquidSensor done: 9437 ms
[INFO] [13:10:23.515] Sensor JaCoCoSensor...
[INFO] [13:10:23.578] Analysing ...\target\coverage-reports\jacoco-unit.exec
[INFO] [13:10:30.390] Sensor JaCoCoSensor done: 6875 ms
[INFO] [13:10:30.390] Sensor JaCoCoItSensor...
[INFO] [13:10:30.390] Analysing ...\target\coverage-reports\jacoco-it.exec
[INFO] [13:10:30.469] Sensor JaCoCoItSensor done: 79 ms
[INFO] [13:10:30.484] Sensor SurefireSensor...
[INFO] [13:10:30.484] parsing ...\target\surefire-reports
[INFO] [13:10:30.828] Sensor SurefireSensor done: 344 ms
[INFO] [13:10:30.828] Sensor CpdSensor...
[INFO] [13:10:30.828] SonarEngine is used …
Run Code Online (Sandbox Code Playgroud)

integration-testing code-coverage jacoco sonarqube

6
推荐指数
1
解决办法
8759
查看次数

排除不适用于 Jacoco Gradle 插件

我正在为我的项目设置 Jacoco Gradle 插件。该插件运行良好并生成覆盖率报告,但它不排除我会排除的包。

我想包含的类在 com/xxx/ws/hn/** 中,我想排除的类在 com/xxx/ws/enterprise/** 中。

这是我的 Gradle 脚本:

apply plugin: "jacoco"

jacoco {
    toolVersion = "0.6.2.201302030002"
    reportsDir = file("$buildDir/reports/jacoco")
}

test {
    jacoco{
        excludes = ["com/xx/ws/enterprise/**/*"]
        includes = ["com/xxx/ws/hn/**/*"]
        append = false
    }
}

jacocoTestReport {
    dependsOn test
    description = "Generate Jacoco coverage reports after running tests."
    executionData = files('build/jacoco/test.exec')
    reports {
        xml.enabled true
        html.enabled true
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么吗?我尝试了各种排除模式,包括“。” 包的分隔符而不是“/”,但似乎没有任何作用。任何帮助将不胜感激。

java gradle jacoco

6
推荐指数
1
解决办法
1797
查看次数

Jacoco Gradle jacocoTestReport 任务失败生成报告时出错 - 是一个目录

我正在使用 Gradle 1.6。

我运行以下命令,它适用于所有项目
gradle clean build jacocoTestReport

今天,我看到其中一个项目在“jacocoTestReport”部分失败。PS附上错误日志。

主要的错误行是

12:35:45.920 [ERROR] [org.gradle.BuildExceptionReporter] 引起的: :创建报告时出错
....
12:35:45.924 [ERROR] [org.gradle.BuildExceptionReporter] 引起的:java.io.FileNotFoundException:/production/jenkinsAKS/workspace/MFUSvc/src/java-test/com/thc/ids/ws/mfu/msg/formulary(是一个目录)

需要注意的几点:

  1. 这个项目正在构建罚款没有错误,但今天我看到了这个错误。
  2. 我尝试使用两个/不同版本的 jacoco(如下所示) - jacocoTestReport 任务在使用这两个版本的所有其他项目中都可以正常工作,但在这个版本中失败了。

    jacoco {
    //toolVersion = "0.6.2.201302030002"
    toolVersion = "0.7.0.201403182114"
    // reportsDir = file("$buildDir/customJacocoReportDir")
    }

  3. 在给定的 src/java-test/.../... 路径下,我看到一个有效的 .java 文件和我的工作区(一旦 compileJava 等 Gradle 任务完成,我看到 build/classes/{main, test, integrationTest }/... 文件夹包含一个有效的 .class 文件(对于出现在错误中并说“是一个目录”的那个路径。

知道我错过了什么。

FULL(--stacktrace 或--debug 日志)显示

12:35:45.893 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on task artifact state cache (/production/jenkinsAKS/workspace/MFUSvc/.gradle/1.6/taskArtifacts).
12:35:45.893 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock …
Run Code Online (Sandbox Code Playgroud)

file report gradle jacoco

6
推荐指数
1
解决办法
2万
查看次数

Gradle Jacoco 插件报告零覆盖

在运行 Gradle 的 Jacoco 插件时,我在选定的一组类上报告的代码覆盖率为零。我已经确认所有测试这些类的单元测试都已成功运行。

非常有趣的是,Eclipse 中的 EclEmma 生成了正确的代码覆盖率结果。我已经确认两个工具都使用相同版本的 Jacoco。

我想弄清楚这两种工具之间的区别是什么?我是否需要 Gradle Jacoco 插件的附加配置。

编辑:我的 Gradle Jacoco 输出显示“类 com/.... 的执行数据不匹配”

更新:我在 Eclipse 中打开了 Jacoco 生成的 test.exec 文件。它显示了缺失覆盖率的类执行了 80% 的探测。

java code-coverage gradle jacoco eclemma

6
推荐指数
1
解决办法
5086
查看次数

向 Jacoco 报告隐蔽coverage.ec 文件

我正在尝试为我的 Android 应用程序获取代码覆盖率,我注意到当测试失败时,不会生成 jacoco 报告,只会生成coverage.ec。

有谁知道如何将coverage.ec 文件转换为jacoco 报告?

这对我不起作用:Jacoco 将coverage.ec 转换为没有coverage.em 的报告

祝一切顺利!

约翰尼

android code-coverage jacoco test-coverage

6
推荐指数
0
解决办法
891
查看次数

java.lang.NoClassDefFoundError:失败的解决方案:Lorg/jacoco/agent/rt/internal_14f7ee5 /离线

在更新到Gradle Build Tools 2.1.3和Gradle 2.14.1之后,我在Android项目中看到以下错误.它在我运行应用程序时立即发生.我该如何解决?

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_14f7ee5/Offline;
at com.ourapp.next.conversation.SomeList.SomeListViewModel.$jacocoInit(SomeListViewModel.java)
at com.ourapp.next.conversation.SomeList.SomeListViewModel.(SomeListViewModel.java)
at com.ourapp.next.conversation.SomeList.SomeListAdapterTest.(SomeListAdapterTest.java:26)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_14f7ee5.Offline" on path: …
Run Code Online (Sandbox Code Playgroud)

android jacoco android-gradle-plugin

6
推荐指数
1
解决办法
8793
查看次数

有没有办法仅在新代码上获得单位覆盖率(例如来自 jacoco)?

我的假设场景是这样的:

  • 我已经运行了我的 junit 测试并生成了一个 jacoco 文件
  • 我的 git diff 显示我更改了 10 行代码

现在我的 git diff 和 jacoco 信息的交集是覆盖了更改的 10 行代码中的 7 行。即 - 我对新代码有 70% 的覆盖率。

但我必须手动解决这个问题。

我想要一种自动化的方法来计算覆盖了多少新代码行的百分比。

我的问题是:有没有办法只在新代码上获得单位覆盖率(例如来自 jacoco)?

(请注意,如果您运行扫描仪并使用 JSON API 询问任务结果,我知道sonarqube可以做到这一点analysis.mode=publish- 我正在寻找开发人员可以在本地运行的轻量级东西。)

unit-testing code-coverage jacoco jacoco-maven-plugin

6
推荐指数
2
解决办法
2512
查看次数

jacoco 分支覆盖和声纳条件覆盖有什么区别?

我正在尝试使用 SonarQube Scanner(版本 3.1.0.1141)分析 java 代码。

  • SonarQube 版本:5.6.6
  • 声纳 Java 插件版本:4.12.0.11033
  • 雅可可版本:0.8.0

我已经用这些属性填充了 sonar-project.properties :

# Sonar sources and metadata
sonar.language=java
sonar.sources=src/main
sonar.java.source=1.8
sonar.sourceEncoding=UTF-8
sonar.java.binaries=target/classes
sonar.java.libraries=target/lib

sonar.tests=src/test
sonar.java.coveragePlugin=jacoco
sonar.junit.reportsPath=target/surefire-reports
sonar.surefire.reportsPath=target/surefire-reports
Run Code Online (Sandbox Code Playgroud)

虽然 jacoco 报告给了我一个班级的结果:

  • 覆盖率:84%
  • 分行覆盖率:71%
  • 错过:9
  • 复杂度:24
  • 错过:6
  • 行数:69
  • 错过:0
  • 方法 : 8
  • 错过:0
  • 班级:1

SonarQube 显示测量值:

  • 条件覆盖率62.5%
  • 覆盖率81.7%
  • 线路覆盖率92.8%
  • 行覆盖69
  • 整体状况覆盖率62.5%
  • 总覆盖率81.7%
  • 总线路覆盖率92.8%
  • 整体未覆盖分支15
  • 整体裸露线5
  • 未覆盖的树枝15
  • 未覆盖的线5

根据声纳指标定义页面 …

java code-coverage jacoco sonarqube sonarqube-scan

6
推荐指数
1
解决办法
1万
查看次数

Jacoco 如何正确排除包

我正在使用 Jacoco Maven 插件版本 0.8.1(使用 Java 8 / Maven 3.1.0)。无法让 Jacoco 使用路径排除。我想排除这些包:

  • my.package.model
  • my.package.exception

我试过的:

<build>
      <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>  
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>my.package.model</exclude>
                        <exclude>my.package.exception</exclude>
                    </excludes>
                </configuration>
            </plugin>
      </plugins>
</build>

<reporting>
        <plugins>
             <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.1</version>
                <configuration>
                    <excludes>
                        <exclude>my.package.model</exclude>
                        <exclude>my.package.exception</exclude>
                    </excludes>
                </configuration>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>report</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)

还有(就excludes部分而言):

<excludes>
     <exclude>my.package.model**</exclude>
     <exclude>my.package.exception**</exclude>
</excludes>

<excludes>
     <exclude>my/package/model/**/*</exclude>
     <exclude>my/package/exception/**/*</exclude>
</excludes>

<excludes>
     <exclude>*/my/package/model/**/*</exclude>
     <exclude>*/my/package/exception/**/*</exclude>
</excludes>

<excludes>
     <exclude>**/my/package/model/**/*</exclude>
     <exclude>**/my/package/exception/**/*</exclude>
</excludes>

<excludes> …
Run Code Online (Sandbox Code Playgroud)

java maven jacoco

6
推荐指数
2
解决办法
2万
查看次数

如何为多模块项目添加最小覆盖率规则作为累积数

鉴于使用Gradle 5.0构建的多模块项目,我想使用 jacoco 强制执行所有代码覆盖率。我能够在模块级别设置覆盖强制。但是由于依赖关系的性质,许多测试都是在一个集成模块中编写的,该模块涵盖了大部分代码。因此,仅当整体代码覆盖率低于特定阈值时,我才希望构建失败。下面是我的 build.gradle,无论我为累积覆盖率设置什么值,构建都不会失败。

apply plugin: 'java'
apply plugin: 'jacoco'

subprojects {
    apply plugin: 'java'
    apply plugin: 'jacoco'

    tasks.withType(JacocoReport).all {
        reports {
            html.enabled true
        }
        check.dependsOn it
    }

    jacocoTestReport {
        executionData = fileTree("$buildDir/jacoco/test.exec")
        subprojects.each {
            sourceSets it.sourceSets.main
            dependsOn it.test
        }
    }

    jacocoTestCoverageVerification {
        executionData fileTree("$buildDir/jacoco/test.exec")

        violationRules {
            rule {
                limit {
                    counter = 'LINE'
                    minimum = 0.5 //individual module coverage level
                }
                failOnViolation true
            }
        }
    }
    tasks.build.dependsOn(jacocoTestReport)
    tasks.build.dependsOn(jacocoTestCoverageVerification)
    jacocoTestReport.mustRunAfter jacocoTestCoverageVerification
    check.dependsOn jacocoTestCoverageVerification  
}

//overall …
Run Code Online (Sandbox Code Playgroud)

code-coverage gradle jacoco

6
推荐指数
0
解决办法
445
查看次数