我想使用JaCoCo和Sonar工具测量集成测试的代码覆盖率.
为此,我启动了使用JaCoCo代理配置的Tomcat 5.5,以便从JaCoCo获取转储文件.
因此,我JAVA_OPTS为此设定:
set JAVA_OPTS=-Xrs -XX:MaxPermSize=256m -XX:PermSize=256m -XX:NewRatio=3 -Xms512m -Xmx1024m -XX:+UseParallelGC -javaagent:C:\dev\servers\jacoco-agent.jar=destfile=C:\dev\servers\jacoco.exec,append=true,includes=my.application.*
Run Code Online (Sandbox Code Playgroud)
当我启动Tomcat时,C:\dev\servers\jacoco.exec会生成文件,但不会填充任何数据.
我的服务器配置中有没有忘记的东西?
问候.
我正在使用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) 我有一个课程如下:
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输出中显示的代码覆盖率.
如果我有一个项目但是现在我有一个多模块项目,我能够使代码覆盖正常工作.
我的应用程序是在api项目中构建的,我的所有集成测试都在一个单独的项目中运行,该项目使用前面模块构建的artefact.
构建运行,但我没有得到代码覆盖率报告,而是我收到信息消息:
由于缺少类目录而跳过JaCoCo执行
我的覆盖率报告文件jacoco-it.exec已创建,但似乎jacoco插件需要运行测试的项目中的类.
有人可以告诉我,当类在另一个模块中时,我需要做些什么才能创建覆盖率报告?
我正在尝试用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) 我在项目中添加了一组没有测试的源代码,我不希望它们破坏我的测试覆盖率统计信息.我在下一个方面配置了Jacoco:
test {
jacoco{
excludes = ['org/bla/**']
includes = ['com/bla/**']
append = false
}
}
jacocoTestReport {
dependsOn test
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled true
html.enabled true
}
classDirectories = fileTree(dir: 'build/classes/main', include: 'com/bla/**')
sourceDirectories = fileTree(dir: 'scr/main/java', include: 'com/bla/**')
}
Run Code Online (Sandbox Code Playgroud)
但无论如何,在生成报告时,Jacoco还包括来自org.bla的类
有人能帮我吗 ?
编辑
经过一些调试后,似乎所有默认输出都添加到org.gradle.testing.jacoco.tasks.JacocoReport#classDirectories私有方法中org.gradle.testing.jacoco.plugins.JacocoPlugin#addDefaultReportTasks
使用此类代码时可见:
jacocoTestReport {
classDirectories = files('build/classes/main/com/bla')
println("-----------------------------------------------------------")
getAllClassDirs().each { File file ->
println(file.absolutePath)
}
println("-----------------------------------------------------------")
getAdditionalClassDirs().each{ File file ->
println(file.absolutePath)
}
} …Run Code Online (Sandbox Code Playgroud) 我最近在eclipse中使用EclEmma插件在我的应用程序中查找JUnits的代码覆盖率并且它工作得很好.
在下一步中,我希望能够找到端到端测试/功能测试的代码覆盖,这些测试/功能测试是从外部调用我们的应用程序(它们驻留在单独的服务器上).
基本上,我们将应用程序打包为jar(我们使用maven)并将其部署在服务器上.我们可以在这个位置触发功能测试.
在这种情况下,有没有办法找到代码覆盖?
我对代码覆盖工具如何工作(以原始语言)的理解是它加载类并根据已被命中的代码部分生成报告.因此,根据这种理解,我不需要访问测试代码.我只需要以某种方式插入的代码覆盖工具为我的应用程序罐子,每当这个罐子的任何代码被调用时,报告将被更新.我的理解是否正确?
注意:如果可以使用其他工具,我可以使用其他代码覆盖率工具.
我有一个带有 Gradle 5.1.1 的 android 项目,我想使用 JaCoCo 生成有关测试代码覆盖率的 HTML 报告。我试图按照一些文章中的说明进行操作,但我所有的尝试都导致了错误。
所有对我有用的都是应用插件“jacoco”(此后成功构建了项目)。
apply plugin: 'jacoco'
Run Code Online (Sandbox Code Playgroud)
但是,一旦我添加了任务“jacocoTestReport”,Gradle 就无法与文件同步,并且出现此错误。
这就是我的任务:
jacocoTestReport {
reports {
html.enabled true
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}}
Run Code Online (Sandbox Code Playgroud)
那是我的错误:
ERROR: Could not find method jacocoTestReport() for arguments [build_8kqk7qvpoocfxfydulk1p4m35$_run_closure3@1aba12a5] on project ':app' of type org.gradle.api.Project.
Run Code Online (Sandbox Code Playgroud)
在“build.gradle”中添加“apply plugin”后,我尝试使用“gradlew clean build”。教程作者成功添加任务并在终端中使用此行获取 jacoco 报告:
gradlew build jacocoTestReport
Run Code Online (Sandbox Code Playgroud)
这是我用来了解如何将 jacoco 添加到项目的文章的链接:
https://reflectoring.io/jacoco/
https://android.jlelse.eu/get-beautiful-coverage-reports-in-your-android-projects-ce9ba281507f
所以我的问题是:有没有办法使用 Gradle 将 Jacoco 添加到 Android 项目?我究竟做错了什么?
为了在这里解决我的问题:Applying JaCoCo to all Android Studio gradle module,我在这里应用了解决方案。到目前为止,这对于具有以下功能的模块来说效果很好
plugins {
id("com.android.library")
}
Run Code Online (Sandbox Code Playgroud)
一旦我将所需的内容添加apply from: '../jacoco/modules.gradle'到标记为 Java 库的模块中
plugins {
id("java-library")
}
Run Code Online (Sandbox Code Playgroud)
我得到一个
Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'android' for project ':lib1' of type org.gradle.api.Project.
Run Code Online (Sandbox Code Playgroud)
我想将其添加apply from到 java 库中,以便也为它们生成 JaCoCo 报告。我在这里想念什么?