如何运行使用的IntelliJ模拟器Android的测试? [英] How do I run android tests in the emulator using IntelliJ?

查看:4903
本文介绍了如何运行使用的IntelliJ模拟器Android的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行为code样品的样品单元测试附带了Android SDK。有些测试运行标准单元测试,没有问题。其他检查,如com.example.android.apis.view.Focus2AndroidTest,使用Android类,因此需要在模拟器中运行,这是一个问题。

我可以运行的应用程序只是在我​​的模拟器的罚款。当我运行测试,虽然我的模拟器启动,然后只是坐在那里。测试从未运行。所有我在的IntelliJ输出窗口看到的是

 等待设备。
/用户/ rfzabick / Android的SDK-mac_x86 /工具/仿真器-avd MyAvd0 -netspeed全-netdelay无
设备连接:模拟器-5554

我在做什么错了?

编辑:
@疯狂codeR的意见后,我切换到Android 4.0.3(API 15)。下面是我的了:
测试开始于下午4点34分...

 等待设备。
/用户/ rfzabick / Android的SDK-mac_x86 /工具/仿真器-avd android4.0.3 - api15 -netspeed全-netdelay没有-wipe数据-no-启动阿尼姆
设备连接:模拟器-5554
设备联机:模拟器-5554
目标设备:模拟器-5554(android4.0.3 - api15)
上传文件
    本地路径:/Users/rfzabick/IdeaProjects/ApiDemos/out/production/Tests/Tests.apk
    远程路径:/data/local/tmp/com.example.android.apis.tests
安装com.example.android.apis.tests
DEVICE shell命令:下午安装-r/data/local/tmp/com.example.android.apis.tests
设备未准备好。等待20秒。
DEVICE shell命令:下午安装-r/data/local/tmp/com.example.android.apis.tests
设备未准备好。等待20秒。
DEVICE shell命令:下午安装-r/data/local/tmp/com.example.android.apis.tests
设备断开连接:模拟器-5554
PKG:/data/local/tmp/com.example.android.apis.tests
运行测试
测试运行startedTest运行失败:未找到设备:com.android.ddmlib.AdbCommandRejectedException
空测试套件。

我logcat中看到的唯一相关的是

  16 01-21:36:22.047:WARN / ActivityManager(91):没有内容提供商找到许可撤销:文件:///data/local/tmp/com.example .android.apis.tests


解决方案

可以运行在模拟器或USB设备正常应用程序?尝试创建新的仿真设备,看看是否有帮助。

我和IDEA 11.0.1,在Windows 4.0.3 Android平台尝试过了,它工作得很好:

 等待设备。
目标设备:模拟器-5554(ICS)
上传文件
    本地路径:D:\\ dev的\\ Android的SDK-WINDOWS \\ \\样品的android-15 \\ ApiDemos \\出\\生产\\测试\\ Tests.apk
    远程路径:/data/local/tmp/com.example.android.apis.tests
安装com.example.android.apis.tests
DEVICE shell命令:下午安装-r/data/local/tmp/com.example.android.apis.tests
PKG:/data/local/tmp/com.example.android.apis.tests
成功
运行测试
试运行startedFinish

您也可以尝试重新启动亚行杀亚行 - 服务器和AVD经理手动启动仿真器。

确认有在模拟器中没有pre-安装ApiDemos应用程序或签名将不匹配。卸载现有ApiDemos,然后尝试部署和运行的IntelliJ IDEA ApiDemos,然后尝试再次运行测试配置。


更新::我们做了一些研究,发现了问题的根源。默认情况下的IntelliJ IDEA设置了应用模块测试模块里面的依赖范围的编译,让所有的生产和测试类编译到单个Test.apk。

相反,范围必须设置为提供,我们将在下次更新修复它。现在,你需要手动校正的截图如下所示:

重建项目和运行测试,再次,这个时候2个单独的APK文件将被部署,一个主要的应用,第二个用于测试,然后将测试运行:

 等待设备。
目标设备:模拟器-5554(ICS)
上传文件
    本地路径:D:\\ dev的\\ Android的SDK-WINDOWS \\ \\样品的android-15 \\ ApiDemos \\出\\生产\\测试\\ Tests.apk
    远程路径:/data/local/tmp/com.example.android.apis.tests
安装com.example.android.apis.tests
DEVICE shell命令:下午安装-r/data/local/tmp/com.example.android.apis.tests
PKG:/data/local/tmp/com.example.android.apis.tests
成功
上传文件
    本地路径:D:\\ dev的\\ Android的SDK-WINDOWS \\ \\样品的android-15 \\ ApiDemos \\出\\生产\\ ApiDemos \\ ApiDemos.apk
    远程路径:/data/local/tmp/com.example.android.apis
安装com.example.android.apis
DEVICE shell命令:下午安装-r/data/local/tmp/com.example.android.apis
PKG:/data/local/tmp/com.example.android.apis
成功
运行测试
试运行startedFinish

I'm trying to run the sample unit tests for the sample code that ships with the android SDK. Some of the tests run as standard unit tests, no problem. Other tests, such as com.example.android.apis.view.Focus2AndroidTest, use android classes, and therefore need to run in the emulator, that is a problem.

I can run applications just fine in my emulator. When I run tests, though, my emulator starts up, and then just sits there. The test never runs. All I see in the output window in IntelliJ is

Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd MyAvd0 -netspeed full -netdelay none
Device connected: emulator-5554

What am I doing wrong?

EDIT: After @CrazyCoder's advice, I switched to android 4.0.3 (API 15). Here's what I got: Testing started at 4:34 PM ...

Waiting for device.
/Users/rfzabick/android-sdk-mac_x86/tools/emulator -avd android4.0.3--api15 -netspeed full -netdelay none -wipe-data -no-boot-anim
Device connected: emulator-5554
Device is online: emulator-5554
Target device: emulator-5554 (android4.0.3--api15)
Uploading file
    local path: /Users/rfzabick/IdeaProjects/ApiDemos/out/production/Tests/Tests.apk
    remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device is not ready. Waiting for 20 sec.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
Device disconnected: emulator-5554
pkg: /data/local/tmp/com.example.android.apis.tests


Running tests
Test running startedTest running failed: com.android.ddmlib.AdbCommandRejectedException: device not found
Empty test suite.

The only relevant thing I see in logcat is

01-21 16:36:22.047: WARN/ActivityManager(91): No content provider found for permission revoke: file:///data/local/tmp/com.example.android.apis.tests

解决方案

Can you run normal apps in the emulator or USB device? Try to create the new emulator device and see if helps.

I've tried it with IDEA 11.0.1, 4.0.3 Android platform on Windows and it works fine:

Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
    local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
    remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Success


Running tests
Test running startedFinish

You can also try to restart adb with adb kill-server and start the emulator manually from AVD manager.

Verify that there is no pre-installed ApiDemos application in the emulator, or the signatures will not match. Uninstall existing ApiDemos, then try to deploy and run ApiDemos from IntelliJ IDEA, then try to run the test configuration again.


UPDATE: We did some research and found the source of the problem. By default IntelliJ IDEA sets the dependency scope for the application module inside test module to Compile, so that all the production and test classes get compiled into the single Test.apk.

Instead, the scope must be set to Provided and we'll fix it in the next update. Right now you need to correct it manually as shown on the screenshot:

Rebuild the project and run the tests, again, this time 2 separate apk files will be deployed, one for the main app and the second one for the tests, then tests will run:

Waiting for device.
Target device: emulator-5554 (ICS)
Uploading file
    local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\Tests\Tests.apk
    remote path: /data/local/tmp/com.example.android.apis.tests
Installing com.example.android.apis.tests
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis.tests"
pkg: /data/local/tmp/com.example.android.apis.tests
Success


Uploading file
    local path: D:\dev\android-sdk-windows\samples\android-15\ApiDemos\out\production\ApiDemos\ApiDemos.apk
    remote path: /data/local/tmp/com.example.android.apis
Installing com.example.android.apis
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.android.apis"
pkg: /data/local/tmp/com.example.android.apis
Success


Running tests
Test running startedFinish

这篇关于如何运行使用的IntelliJ模拟器Android的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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