Unit testing iOS 10 notifications

前端 未结 3 498
太阳男子
太阳男子 2021-02-05 13:13

In my app I wish to assert that notifications have been added in the correct format. I\'d normally do this with dependency injection, but I can\'t think of a way to test the new

3条回答
  •  一向
    一向 (楼主)
    2021-02-05 13:35

    Although it's most probably correct to test that UNUserNotificationCenter is called and not to test that it actually works (Apple should test that), you do not need any permissions to schedule and then check the scheduled notifications. Permissions are only needed to actually display the notification (and you definitely not testing that in your unit tests).

    In my unit tests, I call through to real UNUserNotificationCenter implementation and then check the scheduled notifications (UNUserNotificationCenter.current().getPendingNotificationRequests) and all of this works without any permissions and the tests run extremely quick. This approach is much faster than the one already proposed (in that sense that you need to write less code to be able to test).

提交回复
热议问题