我正在尝试检查我在Kotlin中编写的测试用例的代码覆盖率.当我执行时./gradlew createDebugCoverageReport --info,我的coverage.ec文件为空,我的报告显示我有0%的覆盖率.请注意,测试用例100%成功.谁能想到我的coverage.ec文件一直返回0字节的原因?
我到处搜寻都没有运气.
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'jacoco'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
testCoverageEnabled = true
}
release {
minifyEnabled false
testCoverageEnabled = true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude …Run Code Online (Sandbox Code Playgroud) 我有2个基于Kotlin的AS项目.一个工作正常,另一个没有.两者都具有相同的结构和gradle配置.我正在使用Kotlin 1.1.4-2和AS 3.0b2.
问题是,当我运行代码覆盖时,我正在测试的类甚至都没有显示在覆盖率报告下.我唯一看到的是R.java和BuildConfig.java,但我的源文件都没有找到.
所有源文件都是基于Kotlin的.我正在使用Spek进行单元测试.与我的其他功能项目相同的设置和版本.我尝试使用JaCoCo和Jetbrains代码覆盖,但都不起作用.
我道歉,我还没能嵌入图片.
这是问题: 报道报道
这是我的项目结构: 文件结构
这是我的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'
}
}
Run Code Online (Sandbox Code Playgroud)
和我的依赖:
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'
Run Code Online (Sandbox Code Playgroud)
我试过跑步
task copyTestClasses(type: Copy) {
from "build/tmp/kotlin-classes/debugUnitTest"
into …Run Code Online (Sandbox Code Playgroud) 在 Android Studio 中运行单元测试用例以获取代码覆盖率后,会出现以下警报提示。重新编译后点击以下错误。
Kotlin: Unsupported plugin option: org.jetbrains.kotlin.android:enabled=true
Run Code Online (Sandbox Code Playgroud)
尝试过的解决方案:
干净的构建
重建
使缓存无效并重新启动
优化进口