2013-07-19 60 views
3

实际上,我想实现它使用下面的类在AndroidJunit测试运行UiAutomatorTestcase项目

  • UIObject的
  • UiSelector
  • UiAutomatorTestcase
的AndroidJunit测试项目中的一个简单的测试套件

单击并打开Android设备上的消息应用程序,然后在Eclipse中将其作为AndroidJunit测试运行。

运行代码时,我得到下面的异常

了java.lang.RuntimeException:存根!

我不明白我要去哪里错了。请让我知道我们是否可以使用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) 
+0

你能发布堆栈从logcat跟踪? – mach

+0

我附上了失败跟踪 –

回答

0

作为标准配置,UI的Automator测试编译并建成一个jar文件,在桌面计算机上,他们然后通过使用adb将jar文件推送到设备来部署到设备。然后他们在设备上运行,在Android运行时通过使用adb shell uiautomator ...感谢https://stackoverflow.com/users/363437/vidstige纠正我之前发布的不准确的帖子。

帮助您运行测试的最快方式可能是将您的代码发布为问题的一部分。

更新2013年7月22日 我还没有看到其他人试图直接在设备上运行测试用例,而不是按照Google(Android)文档的方法构建它们。它可能可能是可能的,但是你可能必须努力工作,以发现你的方法是可能的或可行的。 UIAutomator与Android InstrumentationTestCase框架截然不同。相反,它与GUI进行交互,并且具有能够与各种应用进行交互的优势,包括诸如Android设备内置的设置UI之类的内容。

我建议你从Android开发站点http://developer.android.com/tools/testing/testing_ui.html的文档教程开始,看看你能否得到这个工作。您需要使用运行Android 4.2的设备(或更高版本用于您在Android新版本发布时阅读此内容的设备)。一旦你有了教程的工作,我希望这将是一个很好的起点,为任何你想要编写自动化测试的应用程序编写UIAutomator测试。

欢迎您发布其他更新。

+0

嗨,朱利安我已经附上示例代码到上面的帖子 –

+0

实际上,UiAutomator测试_are_在Android运行时运行。 – vidstige

2

你需要在android设备上运行测试。为了这个工作,代码需要在dexed之前运行,等等。阅读更多here关于如何构建你的测试在android上运行。

运行,像这样

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

official documentation测试。

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

+0

我可以用上面提供的程序运行测试套件。但我的实际担心是检查我们是否可以使用默认的Android测试项目运行Uiautomator juint测试。 –

+0

@RajeshSamson这应该是可能的。 – vidstige

0

您可以像脚本中使用与.SH

ant build 

$youtSdkPath/platform-tools/adb shell  rm /data/local/tmp/ProjectName.jar 
$youtSdkPath/platform-tools/adb push $pathProject/bin/ProjectName.jar /data/local/tmp/ 
$youtSdkPath/platform-tools/adb shell  uiautomator runtest ProjectName.jar -c ClassToTest 

庆典theScript.sh

相关问题