Test menu items

十年热恋 提交于 2019-12-24 16:14:03

问题


I found the following test (slightly modified) as an answer here. But I get an error that says that I need android.permission.INJECT_EVENT. I have added it both to the application-project and the test-project but the test still says it needs it.

Have I missunderstood how the test should be written?

public void testMenuItemAddDrink(){
        Start activity = getActivity();
        ActivityMonitor am = getInstrumentation().addMonitor(Start.class.getName(), null, false);

        getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
        getInstrumentation().invokeMenuActionSync(activity, se.javalia.myDrinks.R.id.menu_addDrink, 0);

        Activity addDrink = getInstrumentation().waitForMonitorWithTimeout(am, 1000);
        assertEquals(true, getInstrumentation().checkMonitorHit(am, 1));
        addDrink.finish();
    }

Thanks in advance Roland


回答1:


You can remove this line:

getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);

it's not necessary because you are using invokeMenuActionSync() instead.



来源:https://stackoverflow.com/questions/5209154/test-menu-items

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