How click on menu option in toolbar using espresso testcase library
<p>I want test "Settings" option in toolbar. On click of "Settings" option, It will  launch new activity and from toolbar title name I want to confirm is it launched successfully launched or not.
Below is the code:-
<strong>java code</strong> </p>

<pre><code>@RunWith(AndroidJUnit4.class)
@SmallTest
public class MainActivityTest {

    @Rule
    public ActivityTestRule&lt;MainActivity&gt; mainActivityActivityTestRule = new ActivityTestRule&lt;&gt;(MainActivity.class);

    @Before
    public void  intialize(){

    }

    @Test
    public void testCanGoToSettings() {
        onView(withId(R.id.toolbar))
                .perform(navigateTo(R.id.action_settings));
        String expectedNoStatisticsText = InstrumentationRegistry.getTargetContext()
                .getString(R.string.action_settings);
        onView(withId(R.id.toolbarSettings)).check(matches(withText(expectedNoStatisticsText)));

    }
</code></pre>

<p>}</p>

<p><strong>xml code</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/home_menu"&gt;
    &lt;item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never" /&gt;
&lt;/menu&gt;
</code></pre>

<p>I am getting below error.</p>

<pre><code>android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.xyz.android.control:id/toolbar
</code></pre>

<p>Kindly help, How I can implement this.</p>