编程语言
首页 > 编程语言> > java-在AndroidJunit测试项目中运行UiAutomatorTestcase

java-在AndroidJunit测试项目中运行UiAutomatorTestcase

作者:互联网

我实际上是在尝试使用以下类的AndroidJunit Test项目中实现一个简单的测试套件

> UiObject
> UiSelector
> UiAutomatorTestcase

在Android设备上单击并打开“消息传递”应用程序,然后在Eclipse中将其作为AndroidJunit Test运行.

在运行代码时,出现以下异常

java.lang.RuntimeException: Stub!

我不明白我要去哪里错了.请让我知道我们是否可以使用AndroidJuint Test项目运行UiAutomatorTestcase测试套件.

这是示例代码和故障跟踪

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();

    }

}

堆栈跟踪

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)

解决方法:

Android 4.3包含一种与Instrumentation http://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation()中的UIAutomation进行交互的方式,并且在http://developer.android.com/about/versions/android-4.3.html#Testing引入了该主题

这似乎是UI测试自动化的另一种形式.我想了解更多关于4.3的UIAutomation和UIAutomator http://developer.android.com/tools/help/uiautomator/index.html之间的交互的信息

标签:uiautomator,android-uiautomator,java,android
来源: https://codeday.me/bug/20191030/1969413.html