Android Studio代码覆盖率未显示任何Kotlin类

24
我有两个基于Kotlin的AS项目,其中一个正常运行,另一个则不行。两个项目具有相同的结构和gradle配置。我正在使用Kotlin 1.1.4-2和AS 3.0b2。
问题在于,当我运行代码覆盖率时,我要测试的类甚至不会出现在覆盖率报告中。我只能看到R.java和BuildConfig.java,但没有发现任何源文件。
所有的源文件都是基于Kotlin的。我正在使用Spek进行单元测试。与我的其他功能性项目相同的设置和版本。我尝试使用JaCoCo和Jetbrains代码覆盖,但都无法正常工作。
很抱歉,我还不能嵌入图片。
这就是问题所在:

coverage report

这是我的项目结构:

file structure

这是我的Gradle Android代码块:

compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName libraryVersion
}

buildTypes {
    debug {
        testCoverageEnabled = true
    }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

和我的依赖关系:

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "io.reactivex.rxjava2:rxkotlin:2.1.0"

testImplementation 'junit:junit:4.12'
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation 'org.jetbrains.spek:spek-api:1.1.2'
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M4'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M4'

implementation 'com.android.support:appcompat-v7:26.0.1'

implementation 'com.squareup.okhttp3:okhttp-ws:3.3.1'
implementation 'com.google.protobuf:protobuf-java:2.6.1'

我尝试运行了。
task copyTestClasses(type: Copy) {
  from "build/tmp/kotlin-classes/debugUnitTest"
  into "build/intermediates/classes/debug"
}

task copySdkClasses(type: Copy) {
  from "build/tmp/kotlin-classes/debug"
  into "build/intermediates/classes/debug"
}

在我的测试之前,这也不起作用。

奇怪的是,使用相同的AS版本、Kotlin版本和项目结构的我的另一个项目正常工作,并生成适当的代码覆盖率。

任何帮助将不胜感激。


是的,在这里也有报告...https://dev59.com/dlcO5IYBdhLWcg3wbBE8 - Elye
这个回答解决了你的问题吗?JaCoCo在Kotlin和Android 3.0中返回0%覆盖率 - Mahozad
2个回答

12

但这对于构建服务器有什么帮助呢? - Ewoks

2

Kotlin宣布推出与JaCoCo和IntelliJ兼容的新kotlinx-kover Gradle插件。
它解决了inline函数的问题,可能还有其他问题。

plugins {
     id("org.jetbrains.kotlinx.kover") version "0.5.0"
}

应用插件后,无需额外配置即可立即使用。

观看YouTube宣传视频并跟踪其在这个YouTrack问题中的路线图。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接