Android tests are not executed

2019-06-26 08:31发布

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

1条回答
Emotional °昔
2楼-- · 2019-06-26 08:40

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.

查看更多
登录 后发表回答