我正在尝试编写一个简单的测试,只需单击主要活动中的MenuItem:
public class doTest extends ActivityInstrumentationTestCase2<doActivity> { public doTest() { super(doActivity.class); } @Override public void setUp() throws Exception { super.setUp(); startActivity(); } private void startActivity() { Intent intent = new Intent(); setActivityIntent(intent); getActivity(); } public void testOne() { Espresso.openContextualActionModeOverflowMenu(); onView(withId(R.id.create_new)).perform(ViewActions.click()); } }
测试失败并显示“NoMatchingViewException”.如果我将onView行更改为:
onView(withText("Add new")).perform(ViewActions.click());
以下是活动的菜单xml:
<item android:id="@+id/create_new" android:title="Add new" tools:ignore="HardcodedText"> </item>
测试工作.为什么matcher withText会找到视图而匹配器却找不到?