Latest 1.1.0
Homepage https://github.com/jonreid/MockUIAlertViewActionSheet
License MIT
Platforms ios 8.0, requires ARC
Authors

Build Status
Coverage Status
CocoaPods Version
Carthage compatible

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?

  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 ViewController tests.

Latest podspec

{
    "name": "MockUIAlertViewActionSheet",
    "version": "1.1.0",
    "summary": "Mock classic alerts and action sheets for unit tests",
    "description": "MockUIAlertViewActionSheet lets you mock old-style iOS alerts and action sheets for unit tests, based on the UIAlertView and UIActionSheet.nnNo actual alerts are presented. This means:nn* The workflow doesn't pause for an action to be selected.n* Tests are blazing fast.",
    "homepage": "https://github.com/jonreid/MockUIAlertViewActionSheet",
    "license": "MIT",
    "authors": {
        "Jon Reid": "[email protected]"
    },
    "social_media_url": "https://twitter.com/qcoding",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/jonreid/MockUIAlertViewActionSheet.git",
        "tag": "v1.1.0"
    },
    "source_files": "Source/MockUIAlertViewActionSheet/*.{h,m}",
    "public_header_files": [
        "Source/MockUIAlertViewActionSheet/QCOMockAlertViewVerifier.h",
        "Source/MockUIAlertViewActionSheet/QCOMockActionSheetVerifier.h"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This