gradle - 在 Jacoco 的 jacocoTestReport.xml 文件中包含多个源集
问题描述
我在基于 Gradle 的项目中定义了一个自定义 sourceSet,如下所示:
sourceSets {
componentTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/componentTest/java')
}
}
}
configurations {
componentTestImplementation.extendsFrom testImplementation
}
task componentTest(type: Test) {
dependsOn assemble
testClassesDirs = sourceSets.componentTest.output.classesDirs
classpath = sourceSets.componentTest.runtimeClasspath
outputs.upToDateWhen { false }
testLogging.showStandardStreams = true
mustRunAfter(test)
}
check.dependsOn(componentTest)
sourceSet 包含 Cucumber 功能。
运行 Jacoco 时,生成的jacocoTestReport.xml文件似乎不包括 Cucumber 测试生成的覆盖率。
这是 Jacoco 配置:
jacocoTestReport {
executionData(
file("${project.buildDir}/jacoco/test.exec"),
file("${project.buildDir}/jacoco/componentTest.exec"),
)
}
我能做些什么来在 xml 文件中获得与在 exec 文件中相同的覆盖率吗?
解决方案
经过进一步的实验,结果证明 xml 文件包含来自 componentTest sourceSet 的覆盖范围。
我问这个问题是因为 SonarQube 中的覆盖范围没有正确反映 - 我无法从 SonarQube 中的 componentTest 中看到 Cucumber 测试。但现在在我看来,实际的覆盖率值与 Jacoco 报告显示的一致。我只需要在 SonarQube 中排除与 Jacoco 中相同的源类。
推荐阅读
- c++ - 使用 constinit 变量初始化 constexpr 变量
- javascript - 在某些浏览器上运行ajax功能时某些div的内容变得模糊
- sql - 我可以将 like where 子句的结果加入另一个表吗
- mpi - MPI_SEND 优于 MPI_ISEND?
- node.js - Azure DevOps 自托管代理报告 NPM 版本错误
- ios - IOS绝对URL改变事件
- java - 如何使用 synchronized 关键字避免过时的数据?
- group-by - FreeMarker 和组
- reactjs - FirebaseUI - 在创建用户之前验证 displayName
- azure - 将订阅活动日志连接到日志分析的策略