Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso test for Notification to showing up

I want to test that when I receive push, Notification will be showing up. And it might be as well to check its properties (like title, set intent and so on.)

How can I do so?

 @Before
public void setupTest() {

    mData.putString(PushNotificator.KEY_PUSH_TYPE, PushType.PROJECT_OFFER.toString());
    mData.putString(PushNotificator.KEY_PUSH_OBJECT, pushObjectJsonString);
    mContext = InstrumentationRegistry.getContext();

}

@Test
public void projectOfferCreatedFromBundle() {
    mPushNotificator = new PushNotificator(mContext);
    mPushNotificator.processPush(mData);
    onView(withText("111")).check(matches(withText("111")));  //how to find notification?
}
like image 285
DmitryBorodin Avatar asked Dec 25 '15 23:12

DmitryBorodin


1 Answers

Espresso UI test framework doesn't see more than actual View. I doubt seriously that you can check any notification with Espresso.

For this purpose use another Googles testing framework uiautomator, which is described as:

UI Automator is a UI testing framework suitable for cross-app functional UI testing across system and installed apps.

Here you would find how to use it with Espresso: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html

More information:
  • Documentation(I): https://google.github.io/android-testing-support-library/docs/uiautomator/index.html
  • Documentation(II): http://developer.android.com/intl/es/training/testing/ui-testing/uiautomator-testing.html

Visit also: Android Testing: UIAutomator vs Espresso

like image 91
piotrek1543 Avatar answered Oct 13 '22 18:10

piotrek1543