gpt4 book ai didi

java - 使用 gradle 从 jacoco 测试覆盖范围中删除一些 java 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:51:46 24 4
gpt4 key购买 nike

我想在 Jacaco 测试覆盖率报告中排除一些源文件。对于其他生成的代码,我是这样做的:

classDirectories = fileTree(
dir: "${project.buildDir}/intermediates/classes/debug/com",
excludes: [
'**/R.class',
'**/R$*.class']
)

但是当我尝试这样做时排除 Java 文件:

   dir: "${project.buildDir}/intermediates/classes/debug/com",
excludes: [
'src//java/com/example/application/Constants.java']

也试过这样:'**/application/Constants.class'。它不起作用。我是否需要在此处包含路径:dir: "${project.buildDir}/intermediates/classes/debug/com"

我使用的是 Android studio 3.0(我认为这里不重要)。我正在尝试的完整代码:

task jacocoTestReport(type: JacocoReport) {
group = "Reporting"
description = "Generate Jacoco coverage reports"
reports {
xml.enabled = true
html.enabled = true
}

sourceDirectories = files(sourceSets)

classDirectories = fileTree(
dir: "${project.buildDir}/intermediates/classes/debug/com",
excludes: [
'src//java/com/example/application/Constants.java', //this is not working
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name.
'**/*Module.*', // Modules for Dagger.
'**/*Dagger*.*', // Dagger auto-generated code.
'**/*MembersInjector*.*', // Dagger auto-generated code.
'**/*_Provide*Factory*.*',
'**/*_Factory.*', //Dagger auto-generated code
'**/*$*$*.*', // Anonymous classes generated by kotlin
//add libraries
'android/**/*.*',
'com/**/*.*',
'uk/**/*.*',
'io/**/*.*',
//remove what we don't test
'androidTest/**/*.*',
'test/**/*.*',
'**/injector/**/*.*',
'**/model/**/*.*',
'**/mock/**/*.*',
'**/event/**/*.*',
'**/**_ViewBinding**',
'**/*EventType.*',
'**/**Mocked'
]

)
executionData = fileTree(dir: 'build/jacoco', include: '**/*.exec')

}

最佳答案

在我的项目中,配置如下:

//exclude the folders we do not want to check
jacocoTestReport {
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'**/enum/**',
'**/util/**',
])
})
}
}

关于java - 使用 gradle 从 jacoco 测试覆盖范围中删除一些 java 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47708230/

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