MockUIAlertController lets you mock iOS alerts and action sheets for unit tests, based on the UIAlertController introduced for iOS 8.
(For old UIAlertView or UIActionSheet mocking, use MockUIAlertViewActionSheet.)
No actual alerts are presented. This means:
- The workflow doesn't pause for an action to be selected
- Tests are blazing fast.
Nothing.
- Instantiate a
QCOMockAlertVerifier
before the execution phase of the test. - Invoke the code to create and present your alert or action sheet.
Information about the alert or action sheet is then available through the QCOMockAlertVerifier.
For example, here's a test verifying the title. sut
is the system under test
in the test fixture.
- (void)testShowAlert_AlertShouldHaveTitle
{
QCOMockAlertVerifier *alertVerifier = [[QCOMockAlertVerifier alloc] init];
[sut showAlert:nil];
XCTAssertEqualObjects(alertVerifier.title, @"Title");
}
See the sample app for more examples. One set of examples use OCHamcrest assertions, but OCHamcrest is not required.
Go through steps 1 and 2 above to present your alert or action sheet using
QCOMockAlertController
. Then call -executeActionForButtonWithTitle:
on your
QCOMockAlertVerifier
with the button title.