我正在尝试检查我在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) 我正在尝试生成Jacoco代码覆盖率报告.我已经在我的测试类中使用了AndroidTestCase.
我发现使用testCoverageEnabled为true并使用默认的android -studio默认jacoco,./ gradlew connectedCheck或createDebugCoverageReport创建成功/失败测试用例的百分比,但没有覆盖率报告.
然后我尝试了jacoco {toolVersion"0.7.1.201405082137"}和任务jacocoTestReport(类型:JacocoReport,dependsOn:"testDebug").我试图用各种任务来改变dependsOn值.该报告显示0(零)测试覆盖率,这是不可能的,因为至少有一半的类被测试.
在过去的几天里,我已经跟踪了堆栈溢出的各种接受的答案.结果是否定的.
我的gradle文件:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "test.gradle.com.myapplicationtestgradle"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(
'proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
jacoco {
version "0.7.1.201405082137"
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
jacoco {
toolVersion "0.7.1.201405082137"
} …Run Code Online (Sandbox Code Playgroud)