Functions
The following functions are available globally.
-
Passes if the bar button item has the specified target/action and the target responds to the action. Fails otherwise.
Declaration
Swift
public func MTKAssertBarButtonItem(_ barButtonItem: UIBarButtonItem, sends action: Selector, to target: NSObject, _ failureMessage: @autoclosure () -> String? = nil, file: StaticString = #file, line: UInt = #line)Parameters
barButtonItemThe bar button item to test.
actionThe message that should be sent to
target.targetThe object that the
actionshould be sent to.failureMessageThe message to log upon failure.
fileThe name of the file to report the failure for. The default value will report the file from which this method is called.
lineThe line number to report the failure for. The default value will report the line number of the calling site.
-
Synchronously tests the provided block for broken constraints. If any constraints are broken, the test fails. Otherwise, it passes.
Declaration
Swift
@discardableResult public func MTKAssertNoBrokenConstraints(message: @autoclosure () -> String? = nil, file: StaticString = #file, line: UInt = #line, testBlock: () -> Void) -> UIntParameters
messageThe message to log upon test failure.
fileThe file the test is called from.
lineThe line number the test is called from.
testBlockThe block to test.
Return Value
Number of broken constraints during test
-
Test that a view controller presented an alert with the specified title, message, action titles, and action styles.
Declaration
Swift
public func MTKAssertAlertIsPresented(by presenter: UIViewController, style: UIAlertControllerStyle, title: String?, message: String?, actions: [ExpectedAlertAction], _ failureMessage: String? = nil, file: StaticString = #file, line: UInt = #line)Parameters
presenterThe view controller expected to have presented the alert.
styleThe expected style of the alert.
titleThe expected title of the alert.
messageThe expected message of the alert.
actionsThe list of expected actions in the expected order.
failureMessageThe message to log upon failure.
fileThe name of the file to report the failure for. The default value will report the file from which this method is called.
lineThe line number to report the failure for. The default value will report the line number of the calling site.
-
Synchronously tests the provided block for exceptions. If it would throw an exception, the exception is caught and the test fails. Otherwise, the test passes.
Warning
You should not rely on
XCTestExpectationfulfillment in this block. If an exception is thrown before fulfillment, the expectation will never be fulfilled.XCTestExpectationshould be unnecessary as the block is executed synchronously.Warning
This will only catch Objective-C-style exceptions. Swift’s
fatalErrors are not caught by this test.Declaration
Swift
@discardableResult public func MTKAssertNoException(message: @autoclosure () -> String? = nil, file: StaticString = #file, line: UInt = #line, testBlock: () -> Void) -> NSException?Parameters
messageThe message to log upon test failure.
fileThe file the test is called from.
lineThe line number the test is called from.
testBlockThe block to test.
Return Value
The caught exception. If no exception was thrown, returns
nil. -
Synchronously tests the provided block for exceptions. If it does not throw an exception, the test fails. If it would throw an exception, the exception is caught and the test passes. Any code below the thrown exception is not executed.
Warning
You should not rely on
XCTestExpectationfulfillment in this block. If an exception is thrown before fulfillment, the expectation will never be fulfilled.XCTestExpectationshould be unnecessary as the block is executed synchronously.Warning
This will only catch Objective-C-style exceptions. Swift’s
fatalErrors are not caught by this test.Declaration
Swift
@discardableResult public func MTKAssertException(message: @autoclosure () -> String? = nil, file: StaticString = #file, line: UInt = #line, testBlock: () -> Void) -> NSException?Parameters
messageThe message to log upon test failure.
fileThe file the test is called from.
lineThe line number the test is called from.
testBlockThe block to test.
Return Value
The caught exception. If no exception was thrown, returns
nil.
-
Test that a control has an action method added for a particular target and event. Passes if the control has the specified target/action/event added. Fails otherwise.
Declaration
Swift
public func MTKAssertControl(_ control: UIControl, sends action: Selector, to target: NSObject, for controlEvent: UIControlEvents, _ failureMessage: @autoclosure () -> String? = nil, file: StaticString = #file, line: UInt = #line)Parameters
controlThe control to test.
actionThe message that should be sent to
targetwhencontrolEventis fired.targetThe object in which
actionshould be invoked on whencontrolEventis fired.controlEventThe event which should trigger
actionontarget.failureMessageThe message to log upon failure.
fileThe name of the file to report the failure for. The default value will report the file from which this method is called.
lineThe line number to report the failure for. The default value will report the line number of the calling site.
-
Test that a segmented control has the expected segment titles in the expectd order. Passes if the segmented control has the specified segment titles in the specified order. Fails otherwise.
Declaration
Swift
public func MTKAssertSegmentedControl(_ segmentedControl: UISegmentedControl, hasSegmentTitles expectedTitles: [String], _ failureMessage: @autoclosure () -> String? = nil, file: StaticString = #file, line: UInt = #line)Parameters
segmentedControlThe segmented control to test.
expectedTitlesThe list of expected segment titles in the expected order.
failureMessageThe message to log upon failure.
fileThe name of the file to report the failure for. The default value will report the file from which this method is called.
lineThe line number to report the failure for. The default value will report the line number of the calling site.
View on GitHub
Functions Reference