Awesome
MockUIAlertViewActionSheet
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.
Adding it to your project
CocoaPods
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
Carthage
Add the following to your Cartfile:
github "jonreid/MockUIAlertViewActionSheet" ~> 1.0
Build It Yourself
Make sure to take everything from Source/MockUIAlertViewActionSheet.
Writing Tests
What do I need to change in production code?
Nothing.
How do I test an alert view?
#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");
}
How do I test an action sheet?
#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.
Can I see some examples?
See the sample app. Run it to see what it does, then read the ViewController tests.