How to test push notifications with UI tests

Automated testing of push notifications on iOS

Paweł Zemsta
AzimoLabs
4 min readSep 12, 2019

--

New software features need to be tested in a variety of different ways. If you don’t do thorough tests, you will break things. When you break things, you lose customers.

At the same time, no company has infinite resources. At Azimo, for instance, we assume that new functionality will be tested manually only once. For the rest, we rely on automated testing.

Why have we invested so much time and money in building automated testing software? Because it saves time and allows us to test more thoroughly than any human could.

Let’s imagine that before each application release, we had to manually test all functionality. Not only would the work be incredibly tedious, but we would risk mistakes thanks to human error.

In addition, the ever-increasing complexity of our application would continue to increase the intensity of our testing schedule. New features must be tested not only for how they work independently, but how they affect existing code. That’s a lot of additional testing.

Eventually, we would spend more time testing than coding, and our release cycle would slip from weekly to monthly and beyond. Automated testing solves that problem.

But not everything can be handled by automatic integration tests, especially those run on simulators. Simulators do not have the same features as a real device, such as push notifications. Testing the full flow of a push notification has always been a manual job, until now. In the step-by-step guide below, I will show you how we automated push notification testing for the Azimo app.

Full flow from sending push to receiving

1. Check whether the tests work on a real device

Assuming that the entire test cycle is run on many simulators running simultaneously, to avoid unnecessary failure of tests, we add the following condition before the name of the test class:

#if !targetEnvironment(simulator)

and at the end of the test class:

#endif

This condition checks whether the tests run on the simulator or on a real device.

2. Launch the application on a real device.

3. Check if the user has push notifications enabled.

In this case, I open the settings screen of the device and check whether the switch responsible for push notification is set to true. If not, I change its value to true by clicking on the switch and then on “Allow” when the permissions pop-up appears.

4. Launch the home screen.

5. Launch Notification Center on the device.

To run the Notification Center, we need to simulate swiping from the top of the device’s screen, which we can do like this:

6. Make a request for push notifications from Braze (the software that manages Azimo’s push notifications).

7. Check that the title and description of the push notification are correct.

Push notification received on device

8. Open the notification and check whether the correct view has been opened in the application and making the appropriate assertion.

View opened after clicked on notification

I hope these steps will help you to build your own automated push notification tests, so that your testing cycle gets faster and your app remains bug-free 😄.

If you have any questions, feel free to post in the comment section.

Towards financial services available to all

We’re working throughout the company to create faster, cheaper, and more available financial services all over the world, and here are some of the techniques that we’re utilizing. There’s still a long way ahead of us, and if you’d like to be part of that journey, check out our careers page.

--

--