Java 使用UIAutomator时获取运行时异常
我跟踪了这个链接 了解如何使用UIAutomator 我遵循了脚本创建的所有步骤 但是当我从Eclipse运行脚本时,我发现了下面的错误。有人能帮我解决这个问题吗Java 使用UIAutomator时获取运行时异常,java,android,junit,ui-automation,Java,Android,Junit,Ui Automation,我跟踪了这个链接 了解如何使用UIAutomator 我遵循了脚本创建的所有步骤 但是当我从Eclipse运行脚本时,我发现了下面的错误。有人能帮我解决这个问题吗 junit.framework.AssertionFailedError: Exception in constructor: test (java.lang.RuntimeException: Stub! at com.android.uiautomator.testrunner.UiAutomatorTestCase.&l
junit.framework.AssertionFailedError: Exception in constructor: test (java.lang.RuntimeException: Stub!
at com.android.uiautomator.testrunner.UiAutomatorTestCase.<init>(UiAutomatorTestCase.java:5)
at SendMessage.<init>(SendMessage.java:10)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at junit.framework.TestSuite.createTest(TestSuite.java:63)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:310)
at junit.framework.TestSuite.addTestsFromTestCase(TestSuite.java:153)
at junit.framework.TestSuite.<init>(TestSuite.java:132)
at org.junit.internal.runners.JUnit38ClassRunner.<init>(JUnit38ClassRunner.java:72)
at org.junit.internal.builders.JUnit3Builder.runnerForClass(JUnit3Builder.java:11)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
)
at junit.framework.Assert.fail(Assert.java:57)
at junit.framework.TestCase.fail(TestCase.java:227)
at junit.framework.TestSuite$1.runTest(TestSuite.java:100)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
有人能解释一下吗?你能用你的代码更新这个问题吗?它看起来像是一个普通的测试用例,而不是一个测试用例。但我不知道如何在Eclipse上实现这一点。这里有一个链接:您是否可以尝试使用命令行-
adb shell uiautomator runtest/data/local/tmp/SendMessage.jar–c SendMessage
?有人能解释一下吗?您能用代码更新问题吗?它看起来像是作为常规测试用例运行,而不是作为测试用例运行。但我不知道如何在Eclipse上实现这一点。这里有一个链接:您能否尝试使用命令行-adb shell uiautomator runtest/data/local/tmp/SendMessage.jar–c SendMessage
?
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class SendMessage extends UiAutomatorTestCase
{
public void test() throws UiObjectNotFoundException
{
findAndRunApp();
}
// Here will be called for all other functions
private void findAndRunApp() throws UiObjectNotFoundException
{
// Go to main screen
getUiDevice().pressHome();
// Find menu button
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
// Click on menu button and wait new window
allAppsButton.clickAndWaitForNewWindow();
// Find App tab
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// Click on app tab
appsTab.click();
// Find scroll object (menu scroll)
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// Set the swiping mode to horizontal (the default is vertical)
appViews.setAsHorizontalList();
// Find Messaging application
UiObject settingsApp = appViews.getChildByText(new UiSelector().className("android.widget.TextView"), "Messaging");
// Open Messaging application
settingsApp.clickAndWaitForNewWindow();
// Validate that the package name is the expected one
UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.android.mms"));
assertTrue("Unable to detect Messaging",settingsValidation.exists());
}
}