title: Unit testing for UNUserNotificationCenter .requestAuthorization in Swift 5
body: <p>I am using test-driven development on Xcode and in Swift to develop an app.</p>
  
  <p>I want to add timed notification alerts to remind people to come back to the app to perform an action. To do that I need to request authorization from my user using the notification center.</p>
  
  <p>To do this, I want to write a test in my unit tests that only passes when the shared UNUserNotificationCenter instance calls its requestAuthorization(options:completionHandler:) method.</p>
  
  <p>I have tried mocking UNUserNotificationCenter:</p>
  
  <pre><code>extension NotificationsExperimentsTests {
  
      class MockNotificationCentre: UNUserNotificationCenter {
  
          var didRequestAuthorization = false
  
          override func requestAuthorization(options: UNAuthorizationOptions = [], completionHandler: @escaping (Bool, Error?) -&gt; Void) {
              didRequestAuthorization = true
          }
      }
  }
  </code></pre>
  
  <p>But then when I try and initialise it in a test,</p>
  
  <pre><code>func test_requestAuthorization_IsCalled() {
  
      var mockNotificationCenter = MockNotificationCentre()
  }
  </code></pre>
  
  <p>the compiler tells me that:</p>
  
  <blockquote>
    <p>'NotificationsExperimentsTests.MockNotificationCentre' cannot be constructed because it has no accessible initializers</p>
  </blockquote>
  
  <p>I'm not sure what to try next, or even whether what I'm trying to do is possible?</p>