Android Kotlin sortedBy方法代码覆盖问题

时间:2019-03-22 18:37:25

标签: android kotlin

我有一种方法可以根据标记“已启用”对给定列表进行排序。当我在测试中调用此方法时,测试运行正常。当我从此方法中删除排序逻辑并仅返回sortedList时,将为整个类生成覆盖率,但是,当我运行带有覆盖率的测试类时,它仅对此方法提供覆盖率。它显示了此输出-

  

(覆盖率):未提取类数据:   com.my.pkg.viewmodel.VariantViewModel $ getSortedVariants $$ inlined $ compareBy $ 1:   java.lang.Throwable com.my.pkg.viewmodel .. *

方法看起来像这样-

fun getSortedVariants() : List<Variant> {
    return sortedList.sortedBy { !it.isEnabled }
 }

对于JaCoCo,该区块为-

def fileFilter = [
        '**/R.class',
        '**/R$*.class',
        '**/BuildConfig.*',
        '**/Manifest*.*',
        '**/*$ViewInjector*.*',
        '**/*$ViewBinder*.*',
        '**/*Test*.*',
        '**/DataBind*.*',
        '**/AppDb_Impl*.*',
        '**/*databinding',
        '**/*$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/my/pkg/generated/*',
        'uk/**/*.*',
        'io/**/*.*',
        //remove what we don't test
        'androidTest/**/*.*',
        'test/**/*.*',
        '**/injector/**/*.*',
        '**/mock/**/*.*',
        '**/**_ViewBinding**',
        '**/*EventType.*',
        '**/**Mocked',
        '**/databinding/**/*.*',
        '**/android/databinding/*Binding.*',
        '**/BR.*',
        '**/R.*',
        '**/R$*.*',
        '**/BuildConfig.*',
        '**/Manifest*.*',
        '**/*_MembersInjector.*',
        '**/Dagger*Component.*',
        '**/Dagger*Component$Builder.*',
        '**/*Module_*Factory.*',
        '**/*ViewPager*.*',
        '**/*ViewHolder*.*',
        '**/*Module*.*'
]

rootProject.subprojects.each { proj ->
    javaClasses   << fileTree(dir: "$proj.buildDir/intermediates/javac/debug", excludes: fileFilter)
    kotlinClasses << fileTree(dir: "$proj.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
    javaSrc       << "$proj.projectDir/src/main/java"
    kotlinSrc     << "$proj.projectDir/src/main/kotlin"
    execution     << fileTree(dir: proj.buildDir,
            includes: ['jacoco/testDebugUnitTest.exec',
                       'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'])
}

但是删除整个fileFilter也没有任何区别。

0 个答案:

没有答案