如何在 Android Studio 中使用 Robotium? [英] How to use Robotium with Android Studio?

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

问题描述

Robotium 是一个 Android 测试自动化框架,完全支持原生和混合应用程序.>

既然 Android Studio 是用于 Android 开发的事实上的 IDE,我有兴趣在 Android Studio 中尝试一下.但是,我找不到设置它的方法.

如何设置和使用 Robotium 在 Android Studio 中进行测试?

解决方案

指南:

  1. 将以下行添加到内部 build.gradle 文件的 dependencies 部分(此文件与 src 文件夹位于同一级别),更改如果需要,版本名称:

    androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'

    如果由于某种原因您不想让 gradle 为您下载依赖项,那么您可以手动添加它们:将robotium.jar 放入libs 文件夹中.右键单击它并选择添加为库...

  2. src 文件夹中创建另一个文件夹 androidTest

  3. 在里面创建java文件夹
  4. (可选步骤,见下文)在其中为测试源创建一个与应用程序包名称相同的包(或在其末尾添加.tests".)
  5. 将光标(在编辑器窗口中)放在您要测试的文件之一(例如 MainActivity)内的类名上,然后按 Alt+Enter.
  6. 选择创建测试.为 Robotium 选择合适的超类:

    android.test.ActivityInstrumentationTestCase2

  7. Android studio 将创建一个测试文件和一个包(如果它不是在第 6 步中创建的)
  8. 如何运行测试:

    • UI:像往常一样使用 Android Studio 运行菜单
    • 控制台:在终端输入以下命令:

      ./gradlew connectedAndroidTest

      HTML 报告将在YourApp/YourApp/build/outputs/reports/androidTests/已连接/index.html"

Robotium is an Android test automation framework that has full support for native and hybrid applications.

Now that Android Studio is the de facto IDE for Android development, I'm interested to try this with Android Studio. However, I couldn't find a way to set it up.

How to setup and use Robotium to test with Android Studio?

解决方案

Guide:

  1. Add the following line to the dependencies section of the inner build.gradle file (this file is located at the same level as src folder), change version name if required:

    androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
    

    If for some reason you don't want to let gradle download dependencies for you then you can add them manually: Place robotium.jar into the libs folder. Right click it and select Add as library...

  2. In the src folder create another folder androidTest

  3. Inside it create java folder
  4. (Optional step, see below) Inside it create a package for the test source with the same name as app’s package name (or add ".tests" to its end.)
  5. Place cursor (in the Editor window) at the class name inside one of the files that you want to test (e.g. MainActivity) and press Alt+Enter.
  6. Select Create Test. Select the proper superclass for Robotium:

    android.test.ActivityInstrumentationTestCase2
    

  7. Android studio will create a test file and a package (if it wasn’t created in step 6)
  8. How to run the test:

    • UI: as usual using Android Studio Run menu
    • console: in the terminal enter the following command:

      ./gradlew connectedAndroidTest
      

      The HTML-reports will be generated at "YourApp/YourApp/build/outputs/reports/androidTests/ connected/index.html"

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

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