我是新手.我使用以下代码.但它为单元测试用例生成了覆盖范围.但它没有为集成测试用例生成.我在包src/test/java中有我的测试类.
test {
dependsOn jettyRunWar
ignoreFailures true
finalizedBy jettyStop
}
apply plugin: 'jacoco'
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
}
Run Code Online (Sandbox Code Playgroud) 我和maven一起经营着sonarqube.
我用以下方式安装它.使用brew,我安装mysql和sonar.
当我运行时,我得到7个严重的错误,但88个测试的代码覆盖率为零

当我使用IntelliJ的工具运行它时,我得到以下结果.(不是零!)

这是我直接检查Jacoco结果的时候.在$base_direc/target/jacoco/index.html

Edit2:我已编辑~/.m2/settings.xml
添加
<properties>
<sonar.host.url>http://localhost:9000/</sonar.host.url>
</properties>
Run Code Online (Sandbox Code Playgroud)
编辑/usr/local/Cellar/sonarqube/6.3.1/libexec/conf/sonar.properties
补充道sonar.host.url=http://localhost:9000/
编辑/usr/local/etc/sonar-scanner.properties补充说 -sonar.host.url=http://localhost:9000/
以上述所有方式运行应用程序并且结果相同,即,我可以看到Jacoco结果但不在声纳中.
是否有可能如果发现错误声纳拒绝进行代码覆盖?!
我正在使用gradle 4.3.1和jacoco插件,我能够在多模块项目中确保一定程度的代码覆盖率.当我将元素设置为CLASS或PACAKAGE时,这很有用,但我很难理解如何让它适用于模块.
看这里我想我要的是管束或集团,但后来当我去覆盖量下jacoco不破.
以下是我所拥有的适用于包级别覆盖实施的示例:
jacocoTestCoverageVerification {
violationRules {
rule {
// should be element = 'BUNDLE' or 'GROUP'?
element = 'PACKAGE'
limit {
minimum = 0.9
}
includes = ['com.mypackage.*']
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我将元素值更改为BUNDLE时,无论覆盖范围如何,构建都不会失败.我希望能够在模块级别控制期望值.
这是我的gradle版本信息:
------------------------------------------------------------
Gradle 4.3.1
------------------------------------------------------------
Build time: 2017-11-08 08:59:45 UTC
Revision: e4f4804807ef7c2829da51877861ff06e07e006d
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_40 (Oracle Corporation 25.40-b25)
OS: …Run Code Online (Sandbox Code Playgroud) 我使用Robolectric和JaCoCo在一起.如果没有gradle脚本中的以下代码行,我的代码覆盖率报告将无效:
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是在最近的Gradle版本中,我在这里使用的JaCoCo扩展标记为已弃用.我找不到任何替代品.那么,我应该在哪里申请includeNoLocationClasses = true?
我一直在通过互联网搜索并询问irc聊天,但他们都没有或没有给出任何答案来试图解决我的问题.
我试图让我的项目JaCoCo在IntellijIDE 上使用,测试将在Jenkins服务器中完成,我已经在我的gradle.build文件中设置了一些设置,JaCoCo但是编译失败说Could not set unknown property 'classDumpFile' for object of type org.gradle.testing.jacoco.plugins.JacocoTaskExtension.
构建文件是这样的:
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'jacoco'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
jacoco{
toolVersion = '0.7.6.201602180812'
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
compile group: 'org.json', name: 'json', version: '20180130'
}
test{
jacoco { …Run Code Online (Sandbox Code Playgroud) 我正在使用Ant,Jacoco和Sonar.当我运行我的构建时,Sonar告诉我"没有关于每次测试覆盖率的信息." 并且Sonar仪表板具有我的覆盖结果,但我无法深入查看它们以查看代码.但是,Jacoco生成的HTML报告确实包含深入到代码中.这是我的承保任务:
<jacoco:coverage destfile="${coverage.output.file}" >
<junit printsummary="on"
errorProperty="test.failed"
failureProperty="test.failed"
haltonfailure="yes"
fork="true">
<formatter type="brief" usefile="false" />
<formatter type="xml" />
<classpath>
<path refid="test.build.class.path"/>
<pathelement location="${test.bin.dir}"/>
</classpath>
<batchtest todir="${results.dir}">
<fileset dir="${test.bin.dir}">
<include name = "**/**/*Test.class"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<jacoco:report>
<executiondata>
<file file="${coverage.output.file}"/>
</executiondata>
<structure name="${ant.project.name}">
<classfiles>
<fileset dir="${bin.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<html destdir="${coverage.results.dir}"/>
</jacoco:report>
</target>
Run Code Online (Sandbox Code Playgroud)
我的声纳目标看起来像这样:
<target name="sonar" depends = "run">
<property name="sonar.jdbc.url" value="..." />
<property name="sonar.jdbc.username" value="...r" />
<property name="sonar.jdbc.password" value="..." />
<property name="sonar.projectKey" value="org.codehaus.sonar:example-java-ant" />
<property …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用jacoco测量我的代码覆盖率,但我不明白黄线的含义.该文件说这是一个没有完全覆盖的情况.但是看到我得到的覆盖快照 - 显然条件被命中因为后续行是绿色的,所以为什么条件标记为黄色?

此外,如果您可以快速参考jacoco可以显示的所有报道项目(除了线路覆盖范围),这将有很大帮助.
我有一个课程如下:
public class XConstants {
public static final int A_TYPE = 1;
public static final int B_TYPE = 2;
}
Run Code Online (Sandbox Code Playgroud)
我在我的测试中使用了这两个变量,但是当我用Jacoco检查测试覆盖率时,它显示了该类的%0测试覆盖率.我的猜测是,因为我从不实例化这个类,只使用它的静态变量.我尝试创建一个实例,测试覆盖率为%100.我怎样才能克服这个问题?
我在Maven项目中使用JACOCO工具.它创建代码覆盖XML文件"jacoco.xml".因为我要解析这个xml,我需要知道xml文件中某些属性的含义.xml包含以下元素:
<sourcefile name="Ops.java">
<line nr="3" mi="0" ci="3" mb="0" cb="0"/>
<line nr="5" mi="0" ci="4" mb="0" cb="0"/>
<line nr="11" mi="0" ci="5" mb="2" cb="2"/>
<line nr="12" mi="0" ci="2" mb="0" cb="0"/>
<line nr="14" mi="8" ci="0" mb="0" cb="0"/>
<line nr="15" mi="2" ci="0" mb="0" cb="0"/>
<counter type="INSTRUCTION" missed="10" covered="14"/>
<counter type="BRANCH" missed="2" covered="2"/>
<counter type="LINE" missed="2" covered="4"/>
<counter type="COMPLEXITY" missed="2" covered="3"/>
<counter type="METHOD" missed="0" covered="3"/>
<counter type="CLASS" missed="0" covered="1"/>
</sourcefile>
Run Code Online (Sandbox Code Playgroud)
变量"nr"似乎表示行号.变量"mi","ci","mb"和"cb"的含义是什么?
这是生成的html输出中显示的代码覆盖率.
我正在尝试用gradle实现声纳,以便为我的项目进行代码覆盖测量.我们使用的是gradle-4.0.1和sonarqube-6.4.
当我从命令行运行gradle sonarqube时,我收到此错误 -
Plugin with id 'org.sonarqube' not found.
Run Code Online (Sandbox Code Playgroud)
我尝试了几个代码更改,但没有运气,请帮忙.我的build.gradle文件如下 -
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'org.sonarqube'
apply plugin: "jacoco"
apply plugin: "java"
apply plugin: "war"
apply plugin: "org.springframework.boot"
sonarqube {
properties {
property "sonar.projectName","Spring4WebService Code Coverage Demo"
property "sonar.projectKey", "org.sonarqubeJacocoCodeCoverage"
property "sonar.reportPath" , "${project.buildDir}/jacoco/test.exec"
}
}
test{
ignoreFailures = true
}
ext {
jacocoVersion = '0.7.6.201602180812'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories …Run Code Online (Sandbox Code Playgroud)