[英]Code coverage in android studio 1.2 for instrumented tests
I have been trying to use the new code coverage feature in Android Studio 1.2. 我一直在尝试使用Android Studio 1.2中的新代码覆盖功能。 There seems to be no documentation for the feature, but so far I figured out to add
似乎没有该功能的文档,但到目前为止我想出来添加
testCoverageEnabled true
to the debug flavor of my Gradle file. 到我的Gradle文件的调试风格。
Still I can only create code coverage reports for JUnit test cases, not instrumented Android test cases. 我仍然只能为JUnit测试用例创建代码覆盖率报告,而不是为已测试的Android测试用例。
Is there any way to generate code coverage for instrumented android test cases ? 有没有办法为检测的android测试用例生成代码覆盖?
In the project build.gradle file (root/build.gradle) add url "https://plugins.gradle.org/m2/"
under the buildscript > repositories sections. 在项目build.gradle文件(root / build.gradle)中,在buildscript> repositories部分下添加
url "https://plugins.gradle.org/m2/"
。 In my project is looks like this: 在我的项目中看起来像这样:
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
The plugin can be applied in the project build.gradle or (as in my case) to the specific module's build.gradle (module/build.gradle): 该插件可以在项目build.gradle或(在我的情况下)应用到特定模块的build.gradle(module / build.gradle):
apply plugin: 'com.vanniktech.android.junit.jacoco'
Apply the plugin at the very top of the build script before you enter the android
section. 在进入
android
部分之前,在构建脚本的最顶部应用插件。
From the Terminal run: 从终端运行:
Windows 视窗
gradlew.bat connectedCheck
Linux (other) Linux(其他)
./gradlew connectedCheck
References: 参考文献:
https://plugins.gradle.org/plugin/com.vanniktech.android.junit.jacoco https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/ https://plugins.gradle.org/plugin/com.vanniktech.android.junit.jacoco https://github.com/vanniktech/gradle-android-junit-jacoco-plugin/
As @Phil H noted, you need to add the jacoco plugin in order to generate reports, and you need to run the connectedCheck in order to run the tests that generate the data. 正如@Phil H指出的那样,您需要添加jacoco插件才能生成报告,并且您需要运行connectedCheck以运行生成数据的测试。 You can find a post here: new link: https://medium.com/@rafael_toledo/setting-up-an-unified-coverage-report-in-android-with-jacoco-robolectric-and-espresso-ffe239aaf3fa with additional details.
你可以在这里找到一个帖子:新链接: https : //medium.com/@rafael_toledo/setting-up-an-unified-coverage-report-in-android-with-jacoco-robolectric-and-espresso-ffe239aaf3fa细节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.