I'm actually trying to implement a simple test suite within an AndroidJunit Test project which uses the following class
to click and open the Messaging application on the Android Device and run it as AndroidJunit Test in Eclipse.
While running the code I'm get the following exception
java.lang.RuntimeException: Stub!
I don't understand where I'm going wrong. Please let me know whether we can run the UiAutomatorTestcase test suite using the AndroidJuint Test project or not.
Here is the sample code and the failure trace
public class UiautomatorTest extends
ActivityInstrumentationTestCase2<MyMainActivity> {
UiAutomatorTestCase mUiAutomatorTestCase;
public UiautomatorTest() {
super(MyMainActivity.class);`enter code here`
// TODO Auto-generated constructor stub
}
@Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
mUiAutomatorTestCase = new UiAutomatorTestCase();
}
public void testToOpenMessageApp() throws UiObjectNotFoundException {
UiObject message = new UiObject(
new UiSelector().description("Messaging"));
message.clickAndWaitForNewWindow();
UiObject composeMessage = new UiObject(
new UiSelector().description("compose"));
composeMessage.clickAndWaitForNewWindow();
UiObject typeMessage = new UiObject(
new UiSelector().description("Type Message"));
typeMessage.clickAndWaitForNewWindow();
mUiAutomatorTestCase.getUiDevice().pressHome();
}
}
The stacktrace
java.lang.RuntimeException: Stub!
at mypackagename.UiAutomatorTestCase.<init>(UiAutomatorTestCase.java:5)
at mypackagename..setUp(UiautomatorTest.java:25)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
You need to run the test on an android device. For this to work the code needs to be dexed before it can be run, etc. Read more here on how to build your test for running on android.
Run the test like so
adb shell uiautomator runtest <JARS> -c <CLASSES> [options]
From the official documentation.
To run your testcases on the target device, you can use the adb shell command to invoke the uiautomator tool.
Android 4.3 includes a way to interact with UIAutomation from Instrumentation http://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation() and the topic is introduced at http://developer.android.com/about/versions/android-4.3.html#Testing
This seems to be another flavour of UI Test Automation. I I'd like to know more about the interaction between 4.3's UIAutomation and UIAutomator http://developer.android.com/tools/help/uiautomator/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With