我想测试一个带有JUnit3和UiAutomatorTestCase类的Android应用程序的GUI,如Google的文档中所述。
我在Eclipse中创建了一个新的Android Test Project并添加了一个非常简单的Test-Class,它应该按下home键并打开菜单。
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被添加到项目中。我在这里看不到我的错误?
答案 0 :(得分:2)
将文件名放在Manifest.xml中