java - 简单的 Android UI 测试找不到测试类

标签 java android unit-testing testing

我想使用 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 添加到项目中。我在这里看不到我的错误吗?

最佳答案

将文件名放入您的 Manifest.xml

关于java - 简单的 Android UI 测试找不到测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16295603/

相关文章:

java - jTSS "There seems no TCS running"

java - 使用 loopj : "Trust anchor for certification path not found."` 时出错

c++ - Thoughtworks游轮 : Unit Testing?

c# - 提高软件质量的最佳实践

java - 摩基托 : How to Verify that a parameter is an Object with a specific parameter?

java - datetimeoffset hibernate 映射

javascript - 在 Java 中访问 JavaScript 对象的字段

android - 如何逻辑地在 xml 中构造 Android View

android - wifi连接改变了android中的 Action

android - 如何在Android Kotlin中保存/使用用户输入