Using TouchUtils in Android testing

谁都会走 提交于 2020-01-06 03:42:44

问题


I'm testing on an actual device, with the screen unlocked. Here's my code:

public class TouchUtilsTest extends ActivityInstrumentationTestCase2<MainActivity> {

    Activity mActivity;
    Instrumentation mInstrumentation;

    public TouchUtilsTest() {
        super(MainActivity.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        setActivityInitialTouchMode(false);

        mActivity = getActivity();
        mInstrumentation = getInstrumentation();
    }

    public void testTapOnView() {
        View v = mActivity.findViewById(3);
        Log.d("testTapOnView", "weee");

        TouchUtils.tapView(this, v);
    }
}

Even with this simple code I run into the following issue:

java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission

I'm not sure what I'm doing wrong... Any suggestions are appreciated.

来源:https://stackoverflow.com/questions/28887133/using-touchutils-in-android-testing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!