gpt4 book ai didi

android - UIAuitomator 代码错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:49:41 25 4
gpt4 key购买 nike

我的代码如下,

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 没有问题。它工作正常。但是这个测试用例有一些错误。你能告诉我如何添加 uiautomator.jar 的 javadocs。因为我找不到 uiautomator 的 javadoc 的 apk?

最佳答案

测试用例需要具有 public void test...() { ... } 的标准 junit 3 样式方法签名

您的代码有一个方法 demo() 一旦您添加了如下前缀测试,testdemo() 就会找到并执行测试。

为了完整起见,这是运行测试时两者之间的区别。首先,使用方法 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();
}
}

关于android - UIAuitomator 代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15631346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com