Android Notification Testing

My Android application has a service that sends notifications to the user based on parameters such as the number of runs of the application. Notifications are sent at different times in different situations. I want to check if notifications are sent at the right time in all different cases. Does android provide a way for such testing?

+5
source share
2 answers

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'` 
+7
source

Read this article

http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html

Here you will find a good explanation of this topic:

Espresso for Android is an ideal and fast testing automation system, but it has one important limitation - you are allowed to work only inside your application in the context of testing.

This means that it is impossible to automate tests for such an application such as:

  • application push notifications
  • contact sync
  • Switching from another application to the application under test

since you have to deal with other applications from your mobile device - NotificationBar , Contacts or People , etc.

In fact, this was not possible until the release of UIAutomator 2.0 . The view says in an Android Developers blog post: "... Most importantly, UI Automator now based on Android Instrumentation ...". And because of which we can run UIAutomator tests, as well as Espresso tests using the Instrumentation test runner .

In addition to this, we can combine UIAutomator tests with Espresso , and this gives us real power and control over the phone and applications.

+1
source

Source: https://habr.com/ru/post/1235101/


All Articles