Mic*_*sel 5 java android jacoco android-gradle-plugin
我一直无法获得代码覆盖率来处理我的任何Android项目.
为简化起见,我创建了一个新项目(选定的空活动).在src/main/java中为项目添加了一个新的实用程序类.
然后我在src/androidTest/java中为它创建了一个单元测试.
更新了gradle文件以启用覆盖.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.michaelkrussel.coverageapp"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
jacoco {
version "0.7.1.201405082137"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
Run Code Online (Sandbox Code Playgroud)
我使用./gradlew createDebugCoverageReport运行测试.单元测试显示我创建的测试通过,但覆盖率报告报告零覆盖.
我假设我要么丢失gradle文件中的某些内容,要么没有运行正确的gradle任务,但我无法弄清楚是什么.
我在我的项目中使用这个配置并且工作正常!
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "br.com.acs.app"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"
testApplicationId "br.com.acs.app.test"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
androidTestCompile 'junit:junit:4.11'
androidTestCompile('com.android.support.test:testing-support-lib:0.1') {
exclude group: 'junit'
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1436 次 |
| 最近记录: |