我想测试我的活动是否有正确数量的菜单项。如何从ActivityInstrumentationTestCase2获取对菜单项的引用?
答案 0 :(得分:0)
看起来应该是这样的:
public class MyTest extends ActivityInstrumentationTestCase2<MyActivity> {
// Snip boilerplate and setUp()
private static final int CORRECT_NUMBER = 5;
public void testMenu() {
MenuClass menu = (MenuClass) getActivity().findViewById(R.id.my_menu);
assert(CORRECT_NUMBER, menu.getAdapter().getCount());
}
}