Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2021 Developer Tools

WWDC21 · 12 min · Developer Tools

Embrace Expected Failures in XCTest

Testing is a crucial part of building a great app: Great tests can help you track down important issues before release, improve your workflow, and provide a quality experience upon release. For issues that can’t be immediately resolved, however, XCTest can help provide better context around those problems with XCTExpectFailure. Learn how this API works, its strict behavior, and how to improve the signal-to-noise ratio in your tests to identify new issues more efficiently.

Watch at developer.apple.com ↗

Transcript all transcripts

Code shown on screen · 7 snippets

XCTSkip unless device is iPad swift · at 3:31 ↗
try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Only supported on iPad")
XCTExpectFailure swift · at 4:31 ↗
XCTExpectFailure("<https://dev.myco.com/bugs/4923> myValidationFunction is returning false")
Scoped XCTExpectFailure swift · at 7:14 ↗
XCTExpectFailure("<https://dev.myco.com/bugs/4923> fix myValidationFunction") {
    XCTAssert(myValidationFunction())
}
XCTExpectFailure with issue matcher swift · at 8:34 ↗
let options = XCTExpectedFailure.Options()
options.issueMatcher = { issue in
    return issue.type == .assertionFailure
}

XCTExpectFailure("<https://dev.myco.com/bugs/4923> fix myValidationFunction", options: options)
Disable XCTExpectFailure for some platforms swift · at 9:03 ↗
let options = XCTExpectedFailure.Options()
#if os(macOS)
options.isEnabled = false
#endif

XCTExpectFailure("<https://dev.myco.com/bugs/4923> fix myValidationFunction", options: options) {
    XCTAssert(myValidationFunction())
}
Disable strict XCTExpectFailure behavior via options swift · at 10:39 ↗
let options = XCTExpectedFailure.Options()
options.isStrict = false

XCTExpectFailure("<https://dev.myco.com/bugs/4923> fix myValidationFunction", options: options) {
    XCTAssert(myValidationFunction())
}
Disable strict XCTExpectFailure behavior via parameter swift · at 10:53 ↗
XCTExpectFailure("<https://dev.myco.com/bugs/4923> fix myValidationFunction", strict: false) {
    XCTAssert(myValidationFunction())
}

Resources