Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running UiAutomatorTestcase in AndroidJunit Test Project

I'm actually trying to implement a simple test suite within an AndroidJunit Test project which uses the following class

  • UiObject
  • UiSelector
  • UiAutomatorTestcase

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)
like image 816
Rajesh Avatar asked Jul 19 '13 18:07

Rajesh


2 Answers

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.

like image 150
vidstige Avatar answered Oct 08 '22 01:10

vidstige


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

like image 21
JulianHarty Avatar answered Oct 08 '22 01:10

JulianHarty