0

I have started learning about UIAutomator in eclipse based on http://university.utest.com/android-ui-testing-uiautomatorviewer-and-uiautomator/. When I wrote a simple code like this:

import static org.junit.Assert.*;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;

import com.android.uiautomator.testrunner.UiAutomatorTestCase;

import com.android.uiautomator.core.UiSelector;

import com.android.uiautomator.core.UiObjectNotFoundException;

import com.android.uiautomator.core.UiScrollable;

import org.junit.Test;

public class test {



@Test
public void test() {
    fail("Not yet implemented");
    getUiDevice().pressHome();
}

}

I get error that getUIDevice() is undefined for the type test. How to improve this?

Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
  • FYI, the documentation you're following is pretty out of date. I'd recommend reading the [official docs](http://developer.android.com/training/testing/ui-testing/uiautomator-testing.html) – Allen Hair Jul 30 '15 at 23:31
  • OK, thanks. During compilation code: `public class testClass extends UiAutomatorTestCase{ @Test public void testWP() throws UiObjectNotFoundException { fail("Not yet implemented"); getUiDevice().pressHome(); } }` i got failure and I do not understand why:`junit.framework.AssertionFailedError: Exception in constructor: testWP (java.lang.RuntimeException: Stub! at com.android.uiautomator.testrunner.UiAutomatorTestCase.(UiAutomatorTestCase.java:5) at testClass.(testClass.java:14) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ` – Teodor Roswelt Jul 31 '15 at 20:26
  • It looks like you're trying to run the test on your host machine. It needs to run on an Android device. See http://stackoverflow.com/questions/17752860/running-uiautomatortestcase-in-androidjunit-test-project – Allen Hair Jul 31 '15 at 21:53

1 Answers1

0

Your test class must extends UiAutomatorTestCase.

Rami Jarrar
  • 4,523
  • 7
  • 36
  • 52