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
barButtonItem
The bar button item to test.
action
The message that should be sent to
target
.target
The object that the
action
should be sent to.failureMessage
The message to log upon failure.
file
The name of the file to report the failure for. The default value will report the file from which this method is called.
line
The 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) -> UInt
Parameters
message
The message to log upon test failure.
file
The file the test is called from.
line
The line number the test is called from.
testBlock
The 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
presenter
The view controller expected to have presented the alert.
style
The expected style of the alert.
title
The expected title of the alert.
message
The expected message of the alert.
actions
The list of expected actions in the expected order.
failureMessage
The message to log upon failure.
file
The name of the file to report the failure for. The default value will report the file from which this method is called.
line
The 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
XCTestExpectation
fulfillment in this block. If an exception is thrown before fulfillment, the expectation will never be fulfilled.XCTestExpectation
should be unnecessary as the block is executed synchronously.Warning
This will only catch Objective-C-style exceptions. Swift’s
fatalError
s 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
message
The message to log upon test failure.
file
The file the test is called from.
line
The line number the test is called from.
testBlock
The 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
XCTestExpectation
fulfillment in this block. If an exception is thrown before fulfillment, the expectation will never be fulfilled.XCTestExpectation
should be unnecessary as the block is executed synchronously.Warning
This will only catch Objective-C-style exceptions. Swift’s
fatalError
s 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
message
The message to log upon test failure.
file
The file the test is called from.
line
The line number the test is called from.
testBlock
The 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
control
The control to test.
action
The message that should be sent to
target
whencontrolEvent
is fired.target
The object in which
action
should be invoked on whencontrolEvent
is fired.controlEvent
The event which should trigger
action
ontarget
.failureMessage
The message to log upon failure.
file
The name of the file to report the failure for. The default value will report the file from which this method is called.
line
The 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
segmentedControl
The segmented control to test.
expectedTitles
The list of expected segment titles in the expected order.
failureMessage
The message to log upon failure.
file
The name of the file to report the failure for. The default value will report the file from which this method is called.
line
The line number to report the failure for. The default value will report the line number of the calling site.