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
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).