2013-03-26 74 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