import android.content.Context; import android.os.SystemClock; import android.provider.Settings; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.UiAutomatorTestCase; import android.support.test.uiautomator.UiDevice; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.*; /** * Instrumentation test, which will execute on an Android device. * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest extends UiAutomatorTestCase { private UiDevice mDevice; @Test public void testdemo() throws Exception { mDevice = getUiDevice(); mDevice.wakeUp(); for (int i = 0; i < 10000; i++) { mDevice.click(380, 380); SystemClock.sleep(500); System.out.print("clicked"); } } }
新建了一个project,然后直接在上面写了一个click,运行结果报空指针,上网查了下说是换成UiDevice.getinstance(),结果又提示没有初始化。
解决方法:@RUNWith(AndroidTUnit4.class) 删掉这一句……
这是新建project的时候自带的