MockUIAlertViewActionSheet 1.1.0

MockUIAlertViewActionSheet 1.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2015

Maintained by Jon Reid.



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

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?

  1. #import <MockUIAlertViewActionSheet/QCOMockAlertViewVerifier.h>
  2. Instantiate a QCOMockAlertViewVerifier before the execution phase of the test.
  3. 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?

  1. #import <MockUIAlertViewActionSheet/QCOMockActionSheetVerifier.h>
  2. Instantiate a QCOMockActionSheetVerifier before the execution phase of the test.
  3. 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 tests.