如何创建测试,Android的工作室? [英] How can I create tests in Android Studio?

查看:149
本文介绍了如何创建测试,Android的工作室?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚下载的Andr​​oid工作室它是基于断的IntelliJ IDE中。

Just downloaded Android Studio which is based off of the Intellij ide.

如何将一个创建测试?

我注意到有用于创建一个测试模块一个选择,但是这似乎并没有做任何事情,只有创建SRC新项目

I notice there is a option for create a Test Module but this doesn't seem to do anything, only create a new project with src

我也试过pressing热键CTRL + ALT + T,允许在现有的类创建单元测试,但它似乎想将其放置在当前项目。当然,这并不能帮助TDD

I also tried pressing the hot key CTRL+AlT+T which allows to create unit tests on an existing class but it seems to want to place it in the current project. Of course this doesn't help with TDD

有没有人在这里的经验吗?

Does anyone have any experience here ?

推荐答案

编辑:由于 0.1.8本现在在IDE 支持。请遵循而不是使用下面的说明中有说明。

As of 0.1.8 this is now supported in the IDE. Please follow the instructions in there, instead of using the instructions below.

Android的摇篮Plugin用户我指南能够通过对新创建的项目执行以下步骤来获得测试工作在命令行(我使用的是默认com.example.myapplication'包):

Following the Android Gradle Plugin User Guide I was able to get tests working on the command line by performing the following steps on a newly created project (I used the default 'com.example.myapplication' package):

  1. 添加一个src / instrumentTest / java目录为测试
  2. 添加一个测试类(延伸ActivityTestCase)在包com.example.myapplication.test
  3. 在启动一个虚拟设备
  4. 在命令行(在MyApplicationProject / MyApplication的目录)使用命令../gradlew connectedInstrumentTest

这跑了我的测试,并放置在测试结果中MyApplicationProject /所有MyApplication /编译/报告/ instrumentTests /连接。我是新来测试Android应用程序,但它似乎很好地工作。

This ran my tests and placed the test results in MyApplicationProject/MyApplication/build/reports/instrumentTests/connected. I'm new to testing Android apps, but it seem to work fine.

在IDE中,这是可能的尝试和运行相同的测试类。您需要

From within the IDE, it's possible to try and run the same test class. You'll need to

  1. 更新build.gradle列出的Maven中央为回购
  2. 更新build.gradle添加的JUnit 3.8作为instrumentTestCompile依赖如instrumentTestCompile'的JUnit:JUnit的:3.8
  3. 在项目结构手动移动JUnit来先在依赖顺序

不过失败(运行测试时缺少测试输出目录中的类路径中使用)。不过,我不知道这会工作不管,因为它是我的理解是一个Android特定的测试运行器是必需的。

However this fails (the classpath used when running the tests is missing the test output directory). However, I'm not sure that this would work regardless as it's my understanding that an Android specific test runner is required.

这篇关于如何创建测试,Android的工作室?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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