MockUIAlertViewActionSheet lets you mock iOS alerts and action sheets for unit tests, based on the classic (and deprecated) UIAlertView and UIActionSheet.
(For new UIAlertController-based alerts, use MockUIAlertController.)
No actual alerts are presented. This means:
- The workflow doesn't pause for an action to be selected
- Tests are blazing fast.
Add the following to your Podfile, changing "MyTests" to the name of your test target:
target :MyTests, :exclusive => true do
pod 'MockUIAlertViewActionSheet', '~> 1.0'
end
Add the following to your Cartfile:
github "jonreid/MockUIAlertViewActionSheet" ~> 1.0
Make sure to take everything from Source/MockUIAlertViewActionSheet.
Nothing.
#import <MockUIAlertViewActionSheet/QCOMockAlertViewVerifier.h>
- Instantiate a
QCOMockAlertViewVerifier
before the execution phase of the test. - Invoke the code to create and present your alert.
Information about the alert is then available through the QCOMockAlertViewVerifier.
For example, here's a test verifying the title. sut
is the system under test
in the test fixture.
- (void)testShowAlert_AlertShouldHaveTitle
{
QCOMockAlertViewVerifier *alertVerifier = [[QCOMockAlertViewVerifier alloc] init];
[sut showAlert:nil];
XCTAssertEqualObjects(alertVerifier.title, @"Title");
}
#import <MockUIAlertViewActionSheet/QCOMockActionSheetVerifier.h>
- Instantiate a
QCOMockActionSheetVerifier
before the execution phase of the test. - Invoke the code to create and present your action sheet.
Information about the action sheet is then available through the QCOMockActionSheetVerifier.
See the sample app. Run it to see what it does, then read the ViewController tests.