4

I have created a test project with exact the same code as shown here:

http://developer.android.com/tools/testing/testing_ui.html

I have uploaded the jar file in the android virtual device and now I'm ready to run the tests. But I always get this output on the console:

INSTRUMENTATION_STATUS: stream=

Test results for WatcherResultPrinter=

Time: 0.0

OK (0 tests)

INSTRUMENTATION_STATUS_CODE: -1


I have also created a simple test with the following code:

public void FailedTest() throws UiObjectNotFoundException {
    assertTrue("This test was executed", false);
}

In case there is something wrong with the code using ui elements.

The package name is Tests and the class name Login so I run the following command:

adb shell uiautomator runtest TestProject.jar -c Tests.Login

Edit

When I run it on a real device I get:

uiautomator: permission denied

chaliasos
  • 9,659
  • 7
  • 50
  • 87

1 Answers1

3

As a first step, can you change the name of the test method to match the standard convention used in jUnit 3 i.e. public void testWhatever() { ... } the first 4 letters of the name nust be 'test' in lower case, the signature is public void and the method does not take any parameters.

Similarly, can you change the package name to the more standard lowercase convention e.g. org.example.tests If you file is called Tests.java (and the class also called Tests) then you should be able to call it as follows:

adb shell uiautomator runtest Tests.jar -c com.example.tests.Tests

If these don't help, please can you revise the question to include the entire code from your Tests.java file?

Note: I've not tried to reproduce your code at this stage as I'm travelling. I can do so if my suggestions don't unblock your problem(s).

I'll follow up on the uiautomator: permission denied separately. UI Automator tests do run on real devices. They don't need the device to be rooted. I run them on standard Android 4.2.x devices.

JulianHarty
  • 3,178
  • 3
  • 32
  • 46
  • When i changed the package and the test method name the test was executed. Thank you very much. – chaliasos Apr 12 '13 at 14:09
  • My device is not rooted. I have also enabled usb debugging. Perhaps it's the android version then (currently only tried on 2.3.x). I will give it a try on android 4. Thank you for your help. – chaliasos Apr 13 '13 at 14:35
  • 1
    Yup, AFAIK you need Android 4.1 or later, and to save you time & frustration, I'll simply recommend you use a device with 4.2.1 or 4.2.2 (but there's a bug in 4.2.2 related to scrolling I've reported to Google). – JulianHarty Apr 13 '13 at 15:44
  • I tried it on Android 4.0.x and I get the error `/system/bin/sh: uiautomator: not found`. On Android 4.1.3 I get an exception when executing the test `NoSuchMethodError: UiScrollable.setAsHorizontalList`. Perhaps I have to run them only on virtual device :) – chaliasos Apr 15 '13 at 09:36
  • 1
    No, no no :) the deal is as follows: UI Automator was introduced with 4.1. However the general impression from my research and others is that 4.1's implementation is either incomplete or broken. 4.2 has a reasonable implementation and should work for you OK on devices with 4.2 installed. But, I discovered a bug in 4.2.2 where the automatic scrolling is broken. Here's a blog post I wrote about my experiences and by workaround for the scrolling bug http://blog.bettersoftwaretesting.com/?p=84 – JulianHarty Apr 15 '13 at 16:11