2013-03-26 21 views
4

我的代碼如下,錯誤UIAuitomator代碼

package com.example.automatorapp.test; 

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

public class Try2 extends UiAutomatorTestCase 
{ 

public void demo() throws UiObjectNotFoundException 
{ 


    getUiDevice().pressHome(); 
} 



} 

,誤差...

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:93) 
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.Pun.<init>(Pun.java:10) 
... 18 more 

我的MainActivity沒有problem.It工作fine.but這一測試案例給出一些錯誤。並且可以告訴我如何添加uautomator.jar的javadoc。因爲我無法找到uautomator的javadoc的apk。

+0

你需要發佈所有相關的代碼 – CocoNess 2013-03-26 07:28:07

回答

1

測試用例需要有public void test...() { ... }

你的代碼標準的JUnit 3風格的方法簽名的demo()方法一旦你添加前綴如下測試,testdemo()那麼測試是發現和執行。

爲了完整起見,這裏是測試運行時2的區別。首先,什麼本質上是一個與方法public void demo()

UIAutomatorExample$ adb shell uiautomator runtest UIAutomatorExample.jar -c com.example.automatoapp.test.Try2 
INSTRUMENTATION_STATUS: stream= 
Test results for WatcherResultPrinter= 
Time: 0.0 

OK (0 tests) 

而且一次你的代碼的方法已經被正確地命名public void testdemo()

UIAutomatorExample$ adb shell uiautomator runtest UIAutomatorExample.jar -c com.example.automatoapp.test.Try2 
INSTRUMENTATION_STATUS: current=1 
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner 
INSTRUMENTATION_STATUS: class=com.example.automatoapp.test.Try2 
INSTRUMENTATION_STATUS: stream= 
com.example.automatoapp.test.Try2: 
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.Try2 
INSTRUMENTATION_STATUS: stream=. 
INSTRUMENTATION_STATUS: numtests=1 
INSTRUMENTATION_STATUS: test=testdemo 
INSTRUMENTATION_STATUS_CODE: 0 
INSTRUMENTATION_STATUS: stream= 
Test results for WatcherResultPrinter=. 
Time: 1.53 

OK (1 test) 

而這裏的示例代碼修正版本:

package com.example.automatoapp.test; 

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

public class Try2 extends UiAutomatorTestCase 
{ 
    public void testdemo() throws UiObjectNotFoundException 
    { 
     getUiDevice().pressHome(); 
    } 
}