我想在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')