在AndroidJunit测试项目运行UiAutomatorTestcase [英] Running UiAutomatorTestcase in AndroidJunit Test Project

查看:2033
本文介绍了在AndroidJunit测试项目运行UiAutomatorTestcase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我其实想实现它使用了下面的类的Andr​​oidJunit测试项目中的一个简单的测试套件


  • UIObject类

  • UiSelector

  • UiAutomatorTestcase

点击并打开Android设备的消息应用程序并运行它作为AndroidJunit测试在Eclipse。

当运行code我得到下面的异常


  

了java.lang.RuntimeException:存根


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

下面是示例code和故障跟踪

 公共类UiautomatorTest扩展
        ActivityInstrumentationTestCase2< MyMainActivity> {    UiAutomatorTestCase mUiAutomatorTestCase;    公共UiautomatorTest(){
        超(MyMainActivity.class);`输入code here`
        // TODO自动生成构造函数存根
    }    @覆盖
    保护无效设置()抛出异常{
        // TODO自动生成方法存根
        super.setUp();
        mUiAutomatorTestCase =新UiAutomatorTestCase();
    }    公共无效testToOpenMessageApp()抛出UiObjectNotFoundException {
        UIObject类的消息=新UIObject类(
                新UiSelector()描述(信息));
        message.clickAndWaitForNewWindow();        UIObject类composeMessage =新UIObject类(
                新UiSelector()描述(撰写));
        composeMessage.clickAndWaitForNewWindow();        UIObject类typeMessage =新UIObject类(
                新UiSelector()描述(类型信息));
        typeMessage.clickAndWaitForNewWindow();
        mUiAutomatorTestCase.getUiDevice()pressHome()。    }}

堆栈跟踪

 了java.lang.RuntimeException:存根!
在mypackagename.UiAutomatorTestCase<&初始化GT;(UiAutomatorTestCase.java:5)
在mypackagename..setUp(UiautomatorTest.java:25)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
在android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
在android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1584)


解决方案

您需要在Android设备上运行测试。对于这项工作的code必须 dexed 之前可以运行它,等这里关于如何建立你的测试运行在Android上阅读更多

运行,像这样的测试

 亚行外壳uiautomator的runTest<罐和GT; -c<课> [选项]

从href=\"http://developer.android.com/tool​​s/help/uiautomator/index.html\" rel=\"nofollow\">官方文档


  

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


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)

解决方案

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.

这篇关于在AndroidJunit测试项目运行UiAutomatorTestcase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆