UIAutomator Test Notification: -
Just go through the code below. This will help you in testing notifications.
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); device.openNotification(); device.wait(Until.hasObject(By.text(NOTIFICATION_TITLE)), TIMEOUT); UiObject2 title = device.findObject(By.text(NOTIFICATION_TITLE)); UiObject2 text = device.findObject(By.text(NOTIFICATION_TEXT)); assertEquals(NOTIFICATION_TITLE, title.getText()); assertEquals(NOTIFICATION_TEXT, text.getText()); title.click(); device.wait(Until.hasObject(By.text(ESPRESSO.getName())), TIMEOUT);`
Remember to add UIAutomator dependencies to build.gradle.
`//UIAutomator dependency androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'`
source share