12

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?
}
appoll
  • 2,910
  • 28
  • 40
DmitryBorodin
  • 4,584
  • 4
  • 17
  • 29

1 Answers1

18

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:

Visit also: Android Testing: UIAutomator vs Espresso

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • 1
    This requires api 18 and above, I'm currently supporting 15. Can I set up instrumentation tests only for 18 and keep project minSDK 15? – DmitryBorodin Dec 26 '15 at 20:16
  • 1
    it means only that you won't run your instrumentation tests on devices with lower API than the latest Jelly Bean. I think you can still keep minSDK as 15 – piotrek1543 Dec 26 '15 at 21:20
  • 1
    Yes, you can keep minSDK as 15 and set test minSD as 18. Check this link: http://qathread.blogspot.ca/2015/05/espresso-uiautomator-perfect-tandem.html – YYamil Aug 11 '16 at 21:52