Skip to content
Mock NSNotificationCenter and test your NSNotification logic with ease
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Release 0.1.0 Jan 12, 2016
Pod Update to Swift 4. Aug 23, 2018
NSNotificationCenterMock.podspec Fix typo Jan 13, 2016


Version License Platform


To run the example project, clone the repo, and run pod install from the Example directory first.

Then, navigate to NSNotificationCenterMock_ExampleTests/NSNotificationCenterMock_ExampleTests.swift and see how the test case utilises NSNotificationCenterMock to test the example app.


NSNotificationCenterMock is available through CocoaPods. To install it, simply add the following line to your Podfile for your testing target:

target 'YourAppTests' do
    pod 'NSNotificationCenterMock'


NSNotificationCenterMock provides the following public methods:

  • hasRegisteredNotificationName(name:_, withSelector:_) -> Bool
    • Returns whether an observer has been registered for NSNotification name with target selector withSelector.
  • hasNotificationBeenPosted(notificationName:_) -> Bool
    • Returns whether a NSNotification named notificationName has been posted.
  • timesNotificationPosted(notificationName:_) -> Int
    • Returns how many times a NSNotification named notificationName has been posted.
  • registeredNotifications() -> Int
    • Returns how many notification the observer has registered too.
  • hasRegisteredNotifications() -> Bool
    • Returns a boolean indicating whether the observer has registered to any notifications or not.




NSNotificationCenterMock is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.