测试菜单项 [英] Test menu items

查看:115
本文介绍了测试菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里找到了以下测试(略作修改)作为答案.但是我收到一条错误消息,提示我需要android.permission.INJECT_EVENT.我已经将其添加到应用程序项目和测试项目中,但是测试仍然表明需要它.

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();
    }

先谢谢了 罗兰(Roland)

Thanks in advance Roland

推荐答案

您可以删除以下行:

getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);

不必要,因为您使用的是invokeMenuActionSync().

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

这篇关于测试菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆