前端开发app程序 用什么模拟器测试安卓_如何运行使用的IntelliJ模拟器Android的测试?...

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android Studio是一种用于开发Android应用程序的集成开发环境(IDE)。它是基于IntelliJ IDEA开发的,并提供了许多功能和工具,使开发人员能够更轻松地创建和调试Android应用程序。 要开始使用Android Studio开发应用程序,首先需要从官方网站或其他可信来源下载Android Studio的安装程序。下载完成后,运行安装程序并按照提示进行安装。 安装完成后,打开Android Studio,将看到一个欢迎界面。从这里可以选择创建新的项目或导入现有项目。在创建新项目时,需要选择应用程序的名称、包名和最低支持的Android版本等信息。 一旦项目创建完成,可以在编辑器中编写代码,并使用Android Studio提供的各种工具进行布局设计、调试和构建应用程序。此外,Android Studio还提供了一套丰富的API和SDK,以及对模拟器和真机设备的支持,以便在开发过程中进行测试和调试。 总之,使用Android Studio可以方便地进行Android应用程序的开发和调试。它提供了许多强大的功能和工具,使开发人员能够更高效地创建优质的Android应用程序123 #### 引用[.reference_title] - *1* *2* *3* [使用Android Studio开发Android APP](https://blog.csdn.net/leyang0910/article/details/130855210)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值