如何使用 Android Studio 获得代码覆盖率? [英] How to get code coverage using Android Studio?

查看:35
本文介绍了如何使用 Android Studio 获得代码覆盖率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android Studio 开发应用.
我能够运行测试代码.
但是,我不知道如何在 android studio 中获得代码覆盖率.

我已经看过以下链接.
帮助指南.

最后,在最新的 Android Studio 中,您应该能够通过单击Run with Coverage"按钮来运行您的 JUnit-Run 配置.

<小时>

在 Android Studio 2.1.3 中,标签是 Run Unit tests with Coverage,其中 Unit test 是您的测试配置的名称,如下面的屏幕截图所示:>

I am developing apps using Android Studio.
I was able to run the test code.
But, I do not know how to get code coverage in android studio.

I have already seen the following links.
Android Gradle Code Coverage
But I can't wait for update to v0.6 supporting emma.

Project configuration is as follows.

Main code
MyProject/AppName/src/main/java/mypackage/MyClass.java

Test code
MyProject/AppName/src/instrumentTest/java/mypackage/test/MyClassTest.java

Project configuration
MyProject
├─build.gradle
└─AppName
    ├─build.gradle
    └─src
        ├─main
        │  ├─java
        │  │  └─mypackage
        │  │      └─MyClass.java
        │  ├─res
        │  └─AndroidManifest.xml
        └─instrumentTest
            └─java
                └─mypackage
                    └─test
                        └─MyClassTest.java

解决方案

With the new Android Studio 1.2, you are able to run your unit tests and see the coverage all within the IDE.

First, you'll need to get your unit tests running in the IDE. (if you already can, then skip this step)

This guide and demo will help you.

Secondly, you'll need to create a JUnit Run configuration

Inside this configuraiton, you'll be able to choose

  • Test Kind: "All in Package"
  • Package: [the package where your tests reside, eg: "com.myapp.tests"]
  • Search for tests: Across Module Dependencies (could be diff for your setup)
  • VM -options: -ea
  • Working Directory: [your project's directory]
  • Use classpath of mod: [select your module]

If you have any issue creating your JUnit Run Configuration, you should visit this guide for help.

Lastly, in the latest Android Studio, you should be able to run your JUnit-Run Configuration by clicking on the 'Run with Coverage' button.


In Android Studio 2.1.3 the is label Run Unit tests with Coverage where Unit test is the name of your test configuration as shown in the following screenshot:

这篇关于如何使用 Android Studio 获得代码覆盖率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆