I'm trying to write a simple test where I simply click on a MenuItem that is in the main activity:
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());
  }
}
The test fails with "NoMatchingViewException". If I change the onView line to:
    onView(withText("Add new")).perform(ViewActions.click());
Here is the menu xml for the activity:
 <item
        android:id="@+id/create_new"
        android:title="Add new"
        tools:ignore="HardcodedText">
    </item>
The test works. Why would the matcher withText find the view whereas the matcher withId not find?