我有一个带有Java源代码和Scala测试源的Maven项目.我Jacoco在verify舞台上使用代码覆盖.当我尝试在验证阶段通过添加执行或运行来运行声纳目标时mvn verify sonar:sonar,我最终将Sonar添加两次测试目录:
[INFO] [11:15:34.756] Test directories:
[INFO] [11:15:34.756] /Users/xxx/Documents/workspace/misc/xxx/src/test/scala
[INFO] [11:15:34.756] /Users/xxx/Documents/workspace/misc/xxx/src/test/scala/../scala
Run Code Online (Sandbox Code Playgroud)
这导致分析失败,出现以下错误:
Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project kv-mapper: Can not execute SonarQube analysis: Unable to read and import the source file : '/Users/xxxx/Documents/workspace/misc/xxx/src/test/scala/../scala/xxx/xxxxx/xxx/xxx/xxxxx/xxxxxx.java' with the charset : 'UTF-8'. Duplicate source for resource
Run Code Online (Sandbox Code Playgroud)
我的pom.xml(对于Sonar)看起来像这样.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar.plugin.version}</version>
<!-- no default executions -->
<configuration>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.language>java</sonar.language>
<sonar.jacoco.itReportPath>
${basedir}/target/jacoco.exec
</sonar.jacoco.itReportPath>
<sonar.exclusions>
**/test/*
</sonar.exclusions>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如何将Sonar配置为:
我已经在jacoco.exec文件中捕获了覆盖范围详细信息.它的大小为6Mb.我需要使用maven生成一个覆盖率报告.我试过以下
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>0.7.0.201403182114</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
<!--
Ensures that the code coverage report for integration tests after
integration tests have been run.
-->
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>D:/JaCoCo/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
它正在生成零百分比的覆盖率报告.
在测试之前,jacoco.exec文件的大小为零字节,现在它的大小为6MB.我在pom.xml中缺少什么?
我试图通过Maven做一个简单的JaCoCo报告,我一直得到同样的错误.这是我的插件的片段.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<executions>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.01</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我跑步时,mvn clean install jacoco:check我得到以下内容
无法执行目标org.jacoco:jacoco-maven-plugin:0.7.2.201409121644:check(default-cli)on project ###########:目标org.jacoco的参数'rules':jacoco -maven-plugin:0.7.2.201409121644:检查丢失或无效 - > [帮助1]
我已经尝试将版本从0.6.3更改为0.7.2以及介于两者之间的每个版本.据我所知,这看起来像0.6.3以上的任何版本的有效配置,甚至最初取自他们在下面的链接中找到的示例(我刚刚删除除检查目标之外的所有内容):
http://www.eclemma.org/jacoco/trunk/doc/maven.html
如果我运行-X选项,我得到以下堆栈跟踪:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.7.2.201409121644:check (default-cli) on project science-open: The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.7.2.201409121644:check are missing or invalid
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:220)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116) …Run Code Online (Sandbox Code Playgroud) 使用Jacoco插件在android studio中测试用例失败时未生成代码覆盖率报告.如何跳过失败的测试用例并生成代码覆盖率报告.
我想在Android应用程序中运行我的测试并创建覆盖率报告,因此我将Jacoco配置添加到我的build.gradle文件中,但它不起作用.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "mm"
minSdkVersion 12
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'com.google.code.gson:gson:2.1'
compile files('libs/android-async-http-1.4.4.jar')
compile files('libs/freemarker.jar')
compile files('libs/greendao-1.3.1.jar')
compile files('libs/raygun4android-1.1.0.jar')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.hamcrest:hamcrest-library:1.3'
compile 'junit:junit:4.11'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+' …Run Code Online (Sandbox Code Playgroud) 在Intellij IDEA 14.1.5社区版中,我导入了maven以获取jacoco.exec文件的覆盖范围.遵循的步骤
右键单击导入的模块.
选择分析 - >显示覆盖数据.
提供有效的jacoc.exec文件并单击"show selected"
而不是覆盖我得到错误,因为" 范围内的所有类"没有覆盖
任何人都可以提出错误的建议吗?
我需要使用新的jacoco任务检查最小覆盖率
jacocoTestCoverageVerification
此任务在3.4.1 gradle版本和jacoco插件> = 0.6.3中可用
我可以运行另一个生成带有分支覆盖率的html报告的任务,但现在我想使用该数字来使构建失败.
这是我的代码
buildscript {
ext {
....
}
repositories {
mavenCentral()
maven {
....
}
}
dependencies {
.....
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
jar {
baseName = "coverage-test"
}
dependencies {
// my dependencies
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
wrapper {
gradleVersion = '3.4.1'
}
jacoco {
toolVersion = '0.7.9'
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来排除我的jacoco分析中的特定类方法.我知道"排除"属性,但这仅适用于整个类.
在我的情况下,我已经生成了扭曲覆盖率报告的方法,所以我想从报告中排除它们.
根据此文档 - https://developer.android.com/studio/test/command-line.html#AMOptionsSyntax,可以从Firebase实验室获取代码覆盖率结果.在firebase-community.slack.com的#test-lab中的一些人能够使它工作,但经过几次尝试,我仍然在打墙.
我能够通过遵循本指南获得jacaco和emma的组合代码覆盖率报告,因此我的本地设置没有任何问题,但在尝试向gcloud cmd行提供参数以询问覆盖率数据时会出现问题,并且它会讨论emma覆盖率.
基本上,当我在本地运行此命令时
gcloud beta test android run \
--type instrumentation \
--app app/build/outputs/apk/*-debug-unaligned.apk \
--test app/build/outputs/apk/*-debug-androidTest-unaligned.apk \
--device-ids Nexus6\
--os-version-ids 22 \
--locales en \
--orientations portrait \
--environment-variables coverage=true,coverageFile="/sdcard/coverage.ec" \
--directories-to-pull=/sdcard
Run Code Online (Sandbox Code Playgroud)
我期待生成覆盖率报告,但我在instruments.results文件中得到了这个
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.godaddy.gdm.telephony.uitests.DialerTabTest:
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: test=dialerTabNumberFormattingTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: test=dialerTabNumberFormattingTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_RESULT: stream=
Time: 6.022
OK (1 test)
Error: **Failed to generate emma coverage.**
INSTRUMENTATION_CODE: -1 …Run Code Online (Sandbox Code Playgroud) SonarQube 7.7 针对 Java 项目分析显示以下警告:
不推荐使用属性“sonar.jacoco.reportPath”(JaCoCo 二进制格式)。应改用“sonar.coverage.jacoco.xmlReportPaths”(JaCoCo XML 格式)。
基于 Gradle 的项目配置sonar-project.properties如下:
sonar.projectKey=MyExampleLib
sonar.projectName=MyExample Library
sonar.sources=src/main/java
sonar.jacoco.reportPath=build/jacoco/test.exec
sonar.junit.reportsPath=build/test-results/test
sonar.java.test.binaries=build/classes/test
sonar.java.binaries=build/classes/java/main
sonar.binaries=build/classes
sonar.projectVersion=$libVersion
Run Code Online (Sandbox Code Playgroud)
SonarQube 服务器 URL 是通过以下方式注入的(否则最终会出现“localhost:9000”错误):
SonarQube 分析通过 Jenkins 和JaCoCo 插件v.3.0.4触发,作业配置如下:
我读到 areport.xml被xmlReportPaths. 我怎样才能生成它?