我在Jenkins有一个项目,我想创建一个JaCoCo代码覆盖率报告.如果我跑jacoco:test那么jacoco:report本地它创建正确的文件(.exec,.classes和来源)myproject/target/scala-2.9.1/jacoco所以它的工作原理.
但是当在jenkins上构建时,这只会创建classes目录,这意味着它会获取代码而不是覆盖它的测试,因此我得到0%的代码覆盖率.
有没有人让jacoco以这种方式与sbt合作?
我将我的Ant任务配置为
<target name="test" depends="init">
<jacoco:coverage destfile="target/jacoco.exec">
<junit printsummary="yes" haltonfailure="yes" fork="yes" forkmode="once">
<classpath refid="my_project.path"/>
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest fork="false" todir="target/test-reports">
<fileset dir="test">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
Run Code Online (Sandbox Code Playgroud)
这产生了预期的junit结果.但是,target/jacoco.exec永远不会创建.我在ant test report任务执行期间没有任何错误.
测试:[jacoco:coverage]用覆盖率增强junit
Run Code Online (Sandbox Code Playgroud)... [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0,009 sec报告:[jacoco:report]加载执行数据文件/home/usr/Workspaces/my_project/target/jacoco.exec
BUILD FAILED /home/usr/Workspaces/my_project/build.xml:73:无法读取执行数据文件/home/usr/Workspaces/my_project/target/jacoco.exec
总时间:14秒
好像我错过了一些东西,无法看清楚到底是什么.
我在jenkins工作中运行SonarQube(使用Post-build Actions).我遇到了JaCoCo的以下问题 -
[INFO] [16:57:43.157] Sensor JaCoCoSensor...
[INFO] [16:57:43.157] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/.../target/jacoco.exec
[INFO] [16:57:43.426] Sensor JaCoCoSensor done: 269 ms
Run Code Online (Sandbox Code Playgroud)
结果,我的项目获得了0%的代码覆盖率.找不到为什么没有创建jacoco.exec.
我没有将"JaCoCo"配置为由maven运行(在我的pom.xml中).我知道在过去jacoco.exec无论如何都是创建的(可能是Sonar本身).
我究竟做错了什么?我是否需要在我的pom.xml中配置JaCoCo才能使用?谢谢.
随着cobertura-maven-plugingetter和setter方法可排除使用代码覆盖ignoreTrivial选项.是否还有这种可能性jacoco-maven-plugin?
这是我目前的配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<configuration>
<excludes>
<exclude>com/welovecoding/web/blog/test/**/*.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>amend-unit-test-java-agent-option</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 关于以下信息:
Cobertura没有仪器接口
我想知道如何将spring-data接口添加到coverage结果中,因为@Repository实现类只是在运行时由Spring声明和实例化.
考虑以下界面:
// src/main/java/my/package/MyObjectRepository.java
@Repository
public interface MyObjectRepository {
MyObject findMyObjectByCodeAndName(String code, String name);
}
Run Code Online (Sandbox Code Playgroud)
并进行以下测试:
// src/test/java/my/package/MyObjectRepositoryTest.java
// @RunWith(SpringJUnit4ClassRunner.class) + Spring configuration
public class MyObjectRepositoryTest {
@Autowired
private MyObjectRepository myObjectRepository;
@Test
public void myTest() {
myObjectRepository.findMyObjectByCodeAndName("foo","bar");
}
}
Run Code Online (Sandbox Code Playgroud)
我不介意切换到Jacoco,但我读过它也没有设备接口.
如何涵盖以下案例?关于Mybatis Mapper也会出现同样的问题/问题,它们被声明为接口,但实现它们的具体Java类声明不是由开发人员编写的,而是由运行时的框架编写的.
我已经开了票,但我还在等待答案.
Android Studio 3.1 Canary 8
Build #AI-173.4529993, built on January 6, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.14.14-300.fc27.x86_64
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用jacoco来生成代码覆盖率.但是,当我运行命令时,./gradlew tasks我看不到任何调用的任务jacocoTestReport.
我尝试运行任务时遇到以下错误./gradlew jacocoTestReport:
在根项目'EnumSample'中找不到任务'jacocoTestReport'
这是我的build.gradlew文件:
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 27
defaultConfig {
applicationId "me.androidbox.enumsample"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
}
jacoco …Run Code Online (Sandbox Code Playgroud) 我有一个带有 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)