问题描述
我试图让使用摇篮Android插件0.10.2测试覆盖率报告。但是,我仍然在运行一些测试后不能得到一个覆盖报告。 (connectedAndroidTest)。
I'm trying to get a test coverage report using Gradle Android plugin 0.10.2.But I still can't get a coverage report after running some tests. (connectedAndroidTest).
我的主要模块的build.gradle是:
my main module's build.gradle is :
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
testCoverageEnabled true
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
和项目的构建摇篮的buildscript部分:
and the buildscript section of project's build gradle is :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
在我运行一个 gradlew connectedAndroidTest
从终端,我可以找到覆盖率仪表类
和的
文件夹。但我无法找到建立
文件夹中的code-报道报道
文件夹中的报告
文件夹。 (只有我能看到的是 androidTests
文件夹)
Once I run a gradlew connectedAndroidTest
from terminal, I can find coverage-instrumented-classes
and code-coverage
folder inside the build
folder. But I can't find coverage
folder in the reports
folder. (Only I can see is androidTests
folder)
有什么缺失得到一个jacoco覆盖率报告?
Is there anything missing for getting a jacoco coverage report?
推荐答案
在数百次搜索的答案,得到一个覆盖报告,我终于找到一个确切的答案是我想要的。
Over the hundreds of times searching the answer to getting a coverage report, I finally found an exact answer what I want.
从这个博客帖子,我发现 gradlew createDebugCoverageReport
创建jacoco覆盖报告。
From the this blog post, I found that gradlew createDebugCoverageReport
creates the jacoco coverage report.
此外,从摇篮插件source code ,该插件使用jacoco 0.6.2.201302030002默认。 (因此,不需要 jacoco版本定义如果你要使用默认版本)
Also, from the gradle plugin source code, the plugin uses jacoco 0.6.2.201302030002 by default. (therefore, jacoco version definition is not required if you are going to use a default version)
总之,在本质步骤获得了 jacoco
覆盖报告Android的摇篮插件是:
In summary, the ESSENTIAL steps to get a jacoco
coverage report with Android gradle plugin are:
- 在Android的摇篮插件版本的 0.10.0 或更高(一般在项目的
build.gradle
) - 添加
testCoverageEnabled真正
您想要生成类型(即调试
) - 运行
$ gradlew createDebugCoverageReport
或gradlew connectedCheck
获得jacoco
覆盖报告。
- Android gradle plugin version 0.10.0 or higher (typically in your project's
build.gradle
) - add
testCoverageEnabled true
to the build type you want (i.e.debug
) - run
$ gradlew createDebugCoverageReport
orgradlew connectedCheck
to get ajacoco
coverage report.
您可以找到您的覆盖报告中建立/报告/保险/ {buildType}
。 (即建立/报告/保险/调试
的调试版本)
You can find your coverage report at the build/reports/coverage/{buildType}
. (i.e. build/reports/coverage/debug
for debug build)
(添加多味情况下,从@ odiggity的评论)的
如果您的项目使用多味的配置,使用创建{flavorName} CoverageReport
代替。覆盖报告将在生成构建/报告/保险/ {flavorName} / {buildType}
。
If your project uses multi-flavor configuration, use create{flavorName}CoverageReport
instead. The coverage report will be generated at build/reports/coverage/{flavorName}/{buildType}
.
实例味道的 krInternal 的用的调试的构件类型:
Example for flavor krInternal with debug build type:
- 命令:
./ gradlew createKrInternalDebugCoverageReport
- 在报告genarated为:
建立/报告/保险/ krInternal /调试
- Command:
./gradlew createKrInternalDebugCoverageReport
- Report is genarated at:
build/reports/coverage/krInternal/debug
既然你只能用模拟器上覆盖报告
和设备用root权限
,你会得到常规(非根)设备上运行的命令后出现以下错误:
Since you can only get a coverage report with the emulator
and device with root permission
, you'll get following error after running a command on the regular(non-rooted) device:
05:48:33 E/Device: Error during Sync: Permission denied
java.io.IOException: com.android.ddmlib.SyncException: Permission denied
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:114)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:158)
at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:42)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
Caused by: com.android.ddmlib.SyncException: Permission denied
at com.android.ddmlib.SyncService.doPullFile(SyncService.java:511)
at com.android.ddmlib.SyncService.pullFile(SyncService.java:320)
at com.android.ddmlib.Device.pullFile(Device.java:849)
at com.android.builder.testing.ConnectedDevice.pullFile(ConnectedDevice.java:107)
... 10 more
:myDirections:connectedAndroidTest FAILED
FAILURE: Build failed with an exception.
这篇关于如何使用Android的摇篮插件0.10.0或更高,我收到了jacoco覆盖报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!