Reputation: 3016
I want to test a GUI of an Android App with JUnit3 and the UiAutomatorTestCase class, as described in Google's Documentation.
I created a new Android Test Project in Eclipse and added a really simple Test-Class to it, which should press the home button and open the menu.
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();
}
}
So far, so good. Now, when I run this test on an emulator, it runs into the following error:
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 and UIAutomator are added to the project. I can not see my mistake here?
Upvotes: 0
Views: 878