在 AndroidJunit 测试项目中运行 UiAutomatorTestcase

2024-03-25

我实际上正在尝试在 Android Junit Test 项目中实现一个简单的测试套件,该项目使用以下类

  • UiObject
  • 用户界面选择器
  • UiAutomator测试用例

单击并打开 Android 设备上的 Messaging 应用程序,并在 Eclipse 中将其作为 Android Junit Test 运行。

运行代码时出现以下异常

java.lang.RuntimeException:存根!

我不明白我哪里错了。请告诉我我们是否可以使用 AndroidJuint 测试项目运行 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 设备上运行测试。为此,代码需要是dexed https://stackoverflow.com/questions/7750448/dex-file-in-android在它可以运行之前,等等。阅读更多here http://developer.android.com/tools/testing/testing_ui.html#builddeploy关于如何构建在 Android 上运行的测试。

像这样运行测试

adb shell uiautomator runtest <JARS> -c <CLASSES> [options]

来自官方文档 http://developer.android.com/tools/help/uiautomator/index.html.

要在目标设备上运行测试用例,您可以使用 adb shell 命令调用 uiautomator 工具。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 AndroidJunit 测试项目中运行 UiAutomatorTestcase 的相关文章

随机推荐