我有一个使用Gradle(2.2)+ JaCoCo + Sonar的多模块项目.我正在使用sonar-runner插件,当我执行测试时,我可以在每个模块中看到测试报告build/jacoco/jacoco.exec.到现在为止还挺好.
问题是,我在模块A中进行了一些测试,它们正在测试来自其他模块B的类,因此JaCoCo正在从模块B中识别具有0%代码覆盖率的类.我知道这不是一个好习惯,但必须这样做.
结构示例:
moduleA
src
java
Foo
test
moduleB
src
java
test
TestFoo
Run Code Online (Sandbox Code Playgroud)
然后JaCoCo将展示Foo0%覆盖率的班级.我尝试合并所有模块的结果,但我得到相同的结果,但在一个文件中,所以这不是我想要的.在执行JaCoCo报告时是否有任何选项可以包含其他模块的来源?
谢谢.
我遇到了一个有趣的问题,如果使用的话,Jacoco会报告单位测试下的0%覆盖率@PrepareForTest.
长话短说,我的单元测试是使用@RunWith(PowerMockRunner.class)和@PrepareForTest(SomeStaticMethodClass.class)执行单元测试的组合,需要模拟静态方法.你可以阅读这两篇文章,我就嘲笑静态方法(发表文章1,2).模拟静态方法效果很好.不好的副作用是,当Jacoco使用@PrepareForTest注释运行单元测试时,任何测试的类单元都会被忽略,并且该类的Jacoco报告显示0%的覆盖率.我已经将问题专门针对@PrepareForTest注释.我这样做是通过创建一个简单的POJO单元测试,在该POJO上获得100%的覆盖率,然后在@PrepareForTest单元测试的注释中添加.在添加该注释后,Jacoco报告显示POJO覆盖率为0%.
所以任何人对此都有任何想法?
以下是一些技术信息:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)
Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600)
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
. . .
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
. . .
</plugin>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.6</version>
<scope>test</scope>
</dependency>
<dependency> …Run Code Online (Sandbox Code Playgroud) 我有一个项目,我使用Jacoco来计算代码覆盖率.我在这里使用maven配置:
使用Jenkins,我运行"mvn clean install test".它在/ target/site/jacoco-ut /文件夹中生成报告.如果我打开index.html文件,我会看到:
但是当我在jenkins工作中打开JaCoCo Coverage报告时,我看到了:
它说每个测试覆盖0%的代码.我不明白为什么我在html报告中没有相同的结果.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<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}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures …Run Code Online (Sandbox Code Playgroud) 所以这个问题可能不是真的具体,但无论如何我都会问它.
我正在尝试使用JaCoCo和IntelliJ来收集有关单元测试的报道.但是,我没有任何经验来设置它.
在Netbeans中,您只需安装JaCoCo插件并选择使用coverage进行测试.这在IntelliJ中如何工作?
我已经搞砸了一段时间没有成功.如果有人有一个很好的教程来设置它,我真的很感激!
我继承了一个android项目来设置代码覆盖率.没有为Android做太多事情,而且几乎没有做太多事情,我开始寻找一个有用的教程.令人惊讶的是,前几个教程非常有用,我能够包含jacoco gradle插件并启用代码覆盖.使用jenkins我甚至生成了一份报道报告.到目前为止一切都很好.
然而,在看到报告时,我闻到了一些可疑的东西.测试与覆盖率似乎太小了.进一步的调查揭示了罪魁祸首.
测试本身更多地是作为功能而不是单元编写的.那没关系.但是,项目库的模块中没有测试.相反,库测试是在gui模块中编写的(因为这是使用库的地方).
因此,即使测试涵盖了大多数库功能,也仅为gui模块的内容生成覆盖.
项目
- 桂模块
----桂源
----所有的测试
- 图书馆模块
----图书馆来源
不,我一直在寻找一个有效的解决方案.不幸的是,我能够找到的是如何将单元和集成.exec测试覆盖结果组合成一个报告(或其他基于单元测试的解决方案 - 其中没有一个适用于仪器测试).
我需要的是基于Gui模块测试从库模块生成源代码.
因为我在这里的黑暗中磕磕绊绊,甚至是那样的东西,远远可能吗?
code-coverage jacoco android-gradle-plugin android-instrumentation
在JBoss AS 7集成测试套件中,我们使用JaCoCo进行代码覆盖.我已经有了执行数据.现在,当生成报告时,我得到"无法添加具有相同名称的不同类:..."所以我必须排除一些罐子.
<exclude name="org/jboss/osgi/framework/main/jbosgi-resolver-metadata-1.0.10.jar"/>
Run Code Online (Sandbox Code Playgroud)
问题是只有一个类是重复的(org/jboss/osgi/metadata/internal/AbstractPackageAttribute).我只希望排除特定的类,而不是整个jar.
我试过了:
<exclude name="org/jboss/osgi/framework/main/**/AbstractPackageAttribute*"/>
Run Code Online (Sandbox Code Playgroud)
但这不起作用.是否有一些特殊的语法,比如.../foo.jar!**/ClassName.class?
我有一个带有 jacoco 插件的 Maven 项目,它生成不同格式的报告,例如 html、csv 和 xml。但我只需要 html。我怎样才能指定它?
这是一些代码,我在其中添加 jacoco 插件:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.plugin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
//other plugins
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
然后我运行测试:
mnv clean test
Run Code Online (Sandbox Code Playgroud)
所有报告都出现在“目标”目录中。
我阅读了文档https://www.eclemma.org/jacoco/trunk/doc/maven.html,但我没有找到任何有关如何选择所需格式的信息。我发现它只适用于 Ant 和 Gradle。
我想我错过了一些东西,所以我将不胜感激任何线索。
仪表板上的代码覆盖率显示 0%
构建.gradle 文件
plugins {
id "org.sonarqube" version "2.8"
id "java"
id "idea"
id "jacoco"
}
jacoco {
toolVersion = "0.8.5"
}
jacocoTestReport {
reports {
html.enabled true
xml.enabled true
xml.destination file("${buildDir}/reports/jacoco.xml")
}
}
plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}
sonarqube {
properties {
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.host.url", "http://169.254.1.100:9000"
property "sonar.coverage.jacoco.xmlReportPath", "${buildDir}/reports/jacoco.xml"
}
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
// https://mvnrepository.com/artifact/junit/junit
testCompile 'junit:junit:4.12'
}
check.dependsOn jacocoTestReport
Run Code Online (Sandbox Code Playgroud)
运行这个命令
./gradlew build jacocoTestReport sonarqube
Run Code Online (Sandbox Code Playgroud)
使用正确的代码覆盖率生成 JacocoTestReport
Sonarqube gradle 任务生成此日志
> …Run Code Online (Sandbox Code Playgroud) 几天来我一直在寻找一种解决方案,用于合并Jacoco多模块 Android 项目的多个报告,以便Sonarcloud立即将它们发送出去。我已经检查了大量的 Stackoverflow 帖子和其他内容,例如博客、Github 存储库、Gradle 论坛等,但不幸的是没有一个解决方案适合我。
如果这里有人与我分享示例项目或代码片段,我将非常感激。
Gradle version: 7.0.2
Kotlin version: 1.5.21
JDK: 11
Run Code Online (Sandbox Code Playgroud)
下面的代码片段也不适合我
/**
* Root task that generates an aggregated Jacoco test coverage report for all sub-projects
*/
task jacocoFullReport(type: JacocoReport, group: 'Coverage reports') {
group = 'Reporting'
description = 'Generates an aggregate report from all subprojects'
tasks.withType(Test) {
ignoreFailures true
}
def projects = subprojects
//noinspection GrUnresolvedAccess
dependsOn(projects.jacocoReport)
final source = files(projects.jacocoReport.sourceDirectories)
additionalSourceDirs.setFrom source
sourceDirectories.setFrom source
classDirectories.setFrom files(projects.jacocoReport.classDirectories) …Run Code Online (Sandbox Code Playgroud) 我目前正在我的团队构建的 Android 代码库中设置 Jacoco。我在 Android 方面没有太多经验,但我之前已经在 Spring Boot 代码库中设置了 Jacoco,以便我可以跟踪 Sonarqube 中的测试覆盖率。但我在 Android 代码库中遇到了困难。
\n所以目录布局看起来像这样
\nMyApp/\n\xe2\x94\x9c\xe2\x94\x80 app/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 build/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 src/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 build.gradle.kts\n\xe2\x94\x9c\xe2\x94\x80 buildSrc/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 build.gradle.kts\n\xe2\x94\x9c\xe2\x94\x80 modules/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 module1/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 src/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 build.gradle.kts\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 module2/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 src/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 build.gradle.kts\n\xe2\x94\x9c\xe2\x94\x80 build.gradle.kts\n\xe2\x94\x9c\xe2\x94\x80 gradle.properties\n\xe2\x94\x9c\xe2\x94\x80 gradlew\n\xe2\x94\x9c\xe2\x94\x80 settings.gradle.kts\nRun Code Online (Sandbox Code Playgroud)\n我尝试添加jacoco到MyApp/build.gradle.kts.
plugins {\n id(Dependencies.Plugins.androidApplication) version Dependencies.Versions.androidAppplication apply false\n id(Dependencies.Plugins.androidLibrary) version Dependencies.Versions.androidLibrary apply false\n id(Dependencies.Plugins.hilt) version Dependencies.Versions.hilt apply false\n id(Dependencies.Plugins.openApi) version Dependencies.Versions.openApi\n id(Dependencies.Plugins.kotlinAndroid) version Dependencies.Versions.kotlinAndroid apply …Run Code Online (Sandbox Code Playgroud)