2013-03-26 75 views
1

其实我是UIautomator测试的新手。我做了一个需要测试的课程。任何人都可以告诉我一些步骤,我怎样才能让我的UIAutomator测试用例课程?我已经得到了一些错误,如...UIAutomator中的RunTimeException在Android中测试

java.lang.RuntimeException: Exception during suite construction 
at 

android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238) 
at java.lang.reflect.Method.invokeNative(Native Method) 
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:1661) 
Caused by: java.lang.reflect.InvocationTargetException 
at java.lang.reflect.Constructor.constructNative(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 
at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87) 
at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73) 
at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262) 
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184) 
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:379) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382) 
at android.app.ActivityThread.access$1300(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5041) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.RuntimeException: Stub! 
at com.android.uiautomator.testrunner.UiAutomatorTestCase.<init>(UiAutomatorTestCase.java:5) 
at com.example.automatorapp.test.Test2.<init>(Test2.java:11) 
... 18 more 

和我的代码是...

 package com.example.automatorapp.test; 

    import com.android.uiautomator.core.UiObjectNotFoundException; 
    import com.android.uiautomator.testrunner.UiAutomatorTestCase; 

public class Test2 extends UiAutomatorTestCase 
{ 

    public Test2() 
    { 
    super(); 
    } 

    public void testDemo() throws UiObjectNotFoundException 
    { 

     getUiDevice().pressHome(); 

    } 


} 

PLZ有人帮我吗?

+0

的问题是在你的构造,'超()'不能与空值传递。 – NullPointer 2013-03-26 10:08:03

+0

但是当我在构造函数中传递一些值时,它会给我错误? – Aditya 2013-03-26 10:08:34

+0

只需删除您的构造函数,就不需要它。 – NullPointer 2013-03-26 10:12:10

回答

2

由于空指针已经指出,构造函数需要删除。

这里是修改后的代码(我已编译和成功运行)

package com.example.automatoapp.test; 

import com.android.uiautomator.core.UiObjectNotFoundException; 
import com.android.uiautomator.testrunner.UiAutomatorTestCase; 


public class Test2 extends UiAutomatorTestCase 
{ 
    public void testDemo() throws UiObjectNotFoundException 
    { 
     getUiDevice().pressHome(); 
    } 
} 

对于下文中,所有的命令从命令行运行,而不是在一个IDE

下面是如何我编译&的UIAutomator码推送到设备 ant clean build && adb push bin/UIAutomatorExample.jar /data/local/tmp/

我怎么跑“你的”测试 adb shell uiautomator runtest UIAutomatorExample.jar -c com.example.automatoapp.test.Test2

为了完整这里是输出:

INSTRUMENTATION_STATUS: current=1 
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner 
INSTRUMENTATION_STATUS: class=com.example.automatoapp.test.Test2 
INSTRUMENTATION_STATUS: stream= 
com.example.automatoapp.test.Test2: 
INSTRUMENTATION_STATUS: numtests=1 
INSTRUMENTATION_STATUS: test=testDemo 
INSTRUMENTATION_STATUS_CODE: 1 
INSTRUMENTATION_STATUS: current=1 
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner 
INSTRUMENTATION_STATUS: class=com.example.automatoapp.test.Test2 
INSTRUMENTATION_STATUS: stream=. 
INSTRUMENTATION_STATUS: numtests=1 
INSTRUMENTATION_STATUS: test=testDemo 
INSTRUMENTATION_STATUS_CODE: 0 
INSTRUMENTATION_STATUS: stream= 
Test results for WatcherResultPrinter=. 
Time: 1.535 

OK (1 test) 


INSTRUMENTATION_STATUS_CODE: -1