gpt4 book ai didi

gradle - CorDapp JaCoCo代码覆盖率

转载 作者:行者123 更新时间:2023-12-03 03:18:22 25 4
gpt4 key购买 nike

我有一个基于Corda的项目,其中包含几个CorDapp子项目。我一直在寻找将JaCoCo代码覆盖范围添加到该项目中的方法。我希望在所有子项目JaCoCo报告的汇总报告中绘制一个代码覆盖率报告。

要将JaCoCo添加到具有几个maven子项目的maven项目中,我遵循了此博客条目https://lkrnac.net/blog/2016/10/aggregate-test-coverage-report/。运行构建./gradlew clean test并获取报告后,我们的一名团队成员指出,当我们运行./gradlew clean deployNodes时,白名单的创建不再正确。

我回到了在https://github.com/corda/cordapp-template-kotlin上找到的基本Kotlin CorDapp模板,以排除我们的项目结构/等级是否做错了什么。没有添加JaCoCo,我将看到所有我期望的白名单条目。添加JaCoCo代码后,我只会看到5个默认的Corda白名单条目,而没有看到我添加的契约(Contract)条目。

我正在使用JaCoCo版本0.8.1和工作服版本2.6.3。我所做的更改都在根目录cordapp-template-kotlin的build.gradle文件中:

subprojects {
repositories {
mavenCentral()
}
apply plugin: 'jacoco'
apply plugin: 'java'

group = 'net.lkrnac.blog'
version = '1.0-SNAPSHOT'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
testCompile("junit:junit:4.12")
}

jacoco {
toolVersion = jacoco_version
}

//command for generating subproject coverage reports
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}
}

def publishedProjects = subprojects.findAll()
task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
description = 'Generates an aggregate report from all subprojects'

dependsOn(publishedProjects.test)

additionalSourceDirs = files(publishedProjects.sourceSets.main.allSource.srcDirs)
sourceDirectories = files(publishedProjects.sourceSets.main.allSource.srcDirs)
classDirectories = files(publishedProjects.sourceSets.main.output)
executionData = files(publishedProjects.jacocoTestReport.executionData)

doFirst {
executionData = files(executionData.findAll { it.exists() })
}

reports {
html.enabled = true // human readable
xml.enabled = true // required by coveralls
}
}

coveralls {
sourceDirs = publishedProjects.sourceSets.main.allSource.srcDirs.flatten()
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
}

tasks.coveralls {
dependsOn jacocoRootReport
}

我认为问题出在简单地添加JacocoReport作为参数的任务。有什么想法可以继续覆盖这两个代码,以及如何正确建立白名单?

最佳答案

我设法找到了解决覆盖率/白名单问题的方法。我开始剥 ionic 项目规范中看似不必要的代码,发现删除apply plugin:jacocojacocoTestReport命令以外的所有内容都会产生Jacoco根代码覆盖范围以及必要的白名单。我不需要更改上面的任何其他代码即可使白名单正常工作。

供引用,子项目现在看起来像这样:

subprojects {
apply plugin: 'jacoco'
apply plugin: 'kotlin'

jacoco {
toolVersion = jacoco_version
}

//command for generating subproject coverage reports
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
}
}

关于gradle - CorDapp JaCoCo代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51516660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com