AnthonyMDev / AMTestHelpers

A collection of helpers that make unit testing UIKit easier.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AMTestHelpers

Version License Platform

Installation

AMTestHelpers is available through CocoaPods. To install it, simply add the following line to your test target in your Podfile:

pod "AMTestHelpers"

Usage

Once AMTestHelpers is included in your test target, all calls to the following methods will be stubbed out through the built in method swizzling.

  • UIViewController
    • presentViewController: animated: completion:
    • dismissViewControllerAnimated: completion:
  • UIResponder
    • becomeFirstResponder
    • resignFirstResponder
    • isFirstResponder

UIViewController

When presentViewController: animated: completion: is called, the property AM_testPresentedViewController will be set to the view controller that should be presented and the completion block will then be called sychronously.

When dismissViewController: animated: completion: is called, the property AM_testPresentedViewController will be set to niland the completion block will then be called sychronously.

Example:

func test_nextButtonIsPressed_presentsNextViewController() {
  // when
  viewControllerBeingTested.nextButtonIsPressed()

  // then
  XCTAssert(viewControllerBeingTested.AM_testPresentedViewController is NextViewController)
}

UIResponder

When becomeFirstResponder is called, the property AM_isFirstResponder will be set to true. When resignFirstResponder is called, it will be set to false. isFirstResponder will return the value of AM_isFirstResponder.

UIAlertController

This library adds an executeHandler() function to UIAlertAction and an executeAction(withTitle:) function to UIAlertController that can be used in your unit tests to programtically call the handler for an action on a UIAlertController.

Author

Anthony Miller, AnthonyMDev@gmail.com

License

AMTestHelpers is available under the MIT license. See the LICENSE file for more info.

About

A collection of helpers that make unit testing UIKit easier.

License:MIT License


Languages

Language:Swift 70.7%Language:Objective-C 24.7%Language:Ruby 4.6%