开发者

How do I run android unit tests/functional tests?

Following the "Hello, World" and "Hello, Testing" tutorials I created an android application created with Eclipse, along with a corresponding Android Test Project.

The tests run fine... once. After that, in order for me to run the tests again, I have to close the emulator.

If I don't close the emulator, the Eclipse console get stuck on "Installing instrumentation android.test.InstrumentationTestRunner on device emula开发者_如何学Ctor-5554"... Nothing happens after that.

Here's the output from my program on the second run:

[HelloTest] ------------------------------
[HelloTest] Android Launch!
[HelloTest] adb is running normally.
[HelloTest] Performing android.test.InstrumentationTestRunner JUnit launch
[HelloTest] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'FakePhone'
[HelloTest] Uploading HelloTest.apk onto device 'emulator-5554'
[HelloTest] Installing HelloTest.apk...
[HelloTest] Success!
[HelloTest] Project dependency found, installing: Hello
[Hello] Application already deployed. No need to reinstall. 
[HelloTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554

As you can see it stops at "Launching Instrumentation"... I've also run "adb logcat" and not seen anything interesting.

I've been told to exit out of the application under test in the emulator in order to run the test again. Unfortunately the emulator doesn't have the app pulled up (it's in the normal "locked" position and when unlocked brings up the home screen) and even if I do pull it up then exit, it doesn't seem to let me run my tests again.

All the example videos and tutorials all stop at the first run of a test. I have yet to see anyone anywhere run a test a second time!


What fixed this problem for me was to create a new Android Test Project with New > Other > Android Test Project. Then I created a new JUnit test class with New > JUnit Test Case that extends AndroidTestCase. When you do that I opted to include the setUp() and tearDown() methods and another test method related to the class I was testing. What fixed my problem is removing the @Test keyword(s) that Eclipse inserts before the test methods.

After that the project launched and the test methods ran. Hope this helps.


Found in Dev Guide

"As you update your code, you periodically package and install it on the emulator. The emulator preserves the application and its state data across restarts, in a user-data disk partition. To ensure that the application runs properly as you update it, you may need to delete the emulator's user-data partition. To do so, start the emulator with the -wipe-data option. For more information about the user-data partition and other emulator storage, see Working with Emulator Disk Images."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜