0

我想使用 JUnit3 和 UiAutomatorTestCase 类测试 Android 应用程序的 GUI,如 Google 文档中所述。

我在 Eclipse 中创建了一个新的 Android 测试项目,并为其添加了一个非常简单的测试类,它应该按下主页按钮并打开菜单。

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

import junit.framework.TestCase;

public class SomeTest extends UiAutomatorTestCase {

    public void testDemo() throws UiObjectNotFoundException {

           // Simulate a short press on the HOME button.
          getUiDevice().pressHome();

          // We’re now in the home screen. Next, we want to simulate 
          // a user bringing up the All Apps screen.
          // If you use the uiautomatorviewer tool to capture a snapshot 
          // of the Home screen, notice that the All Apps button’s 
          // content-description property has the value “Apps”.  We can 
          // use this property to create a UiSelector to find the button. 
          UiObject allAppsButton = new UiObject(new UiSelector()
             .description("Apps"));

          // Simulate a click to bring up the All Apps screen.
          allAppsButton.clickAndWaitForNewWindow();
    }

}

到目前为止,一切都很好。现在,当我在模拟器上运行此测试时,它会遇到以下错误:

04-30 08:38:31.900: E/Trace(1839): error opening trace file: No such file or directory (2)
04-30 08:38:31.996: E/AndroidRuntime(1839): FATAL EXCEPTION: main
04-30 08:38:31.996: E/AndroidRuntime(1839): java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{com.some.wit.android.test/android.test.InstrumentationTestRunner}: java.lang.RuntimeException: Could not find test class. Class: com.some.wit.android.test.SomeTest
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4385)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.app.ActivityThread.access$1300(ActivityThread.java:141)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.os.Looper.loop(Looper.java:137)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at java.lang.reflect.Method.invokeNative(Native Method)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at java.lang.reflect.Method.invoke(Method.java:511)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at dalvik.system.NativeStart.main(Native Method)
04-30 08:38:31.996: E/AndroidRuntime(1839): Caused by: java.lang.RuntimeException: Could not find test class. Class: com.some.wit.android.test.SomeTest
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.test.AndroidTestRunner.runFailed(AndroidTestRunner.java:254)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.test.AndroidTestRunner.loadTestClass(AndroidTestRunner.java:88)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.test.AndroidTestRunner.setTestClassName(AndroidTestRunner.java:49)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.test.suitebuilder.TestSuiteBuilder.addTestClassByName(TestSuiteBuilder.java:80)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.test.InstrumentationTestRunner.parseTestClass(InstrumentationTestRunner.java:444)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.test.InstrumentationTestRunner.parseTestClasses(InstrumentationTestRunner.java:425)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:370)
04-30 08:38:31.996: E/AndroidRuntime(1839):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4382)
04-30 08:38:31.996: E/AndroidRuntime(1839):     ... 10 more

JUnit3 和 UIAutomator 被添加到项目中。我在这里看不到我的错误吗?

4

1 回答 1

2

将文件名放入您的 Manifest.xml

于 2013-04-30T09:02:49.390 回答