Let’s mock a UIAlertView with OCMock. Here’s a simple alert:
And a test that ensures that the alert has been displayed.
The only interesting thing here is that you need to stopMocking the class or other tests will still have the mock enabled and will expect show to be called, producing weird and seemingly unrelated errors.
Related to this – if you’re going to be performing actions based on UIAlertView button presses, I highly recommend UIAlertView+Blocks, which lets you write the callback inline with the view. I haven’t figured out how to test that, you can help me on StackOverflow.