-
Triage test failures with XCTIssue
Put your test failures to work: Learn how to triage and diagnose uncaught issues in your app using the latest testing APIs in Xcode. We'll show you how to help ease your testing workflow and put failures into context to help you deliver the best quality product.
For more information on designing your tests to improve triaging, see “Write tests to fail.”
And check out the latest improvements to Xcode's testing workflow by watching “Get your test results faster”, “Handle interruptions and alerts in UI tests”, and “XCTSkip your tests.”Recursos
Vídeos relacionados
WWDC20
-
Buscar neste vídeo...
-
-
9:52 - Implement a custom test assertion using XCTIssue
func assertSomething(about data: Data, file: StaticString = #filePath, line: UInt = #line) { // Call out to custom validation function. if !isValid(data) { // Create issue, declare with var for mutability. var issue = XCTIssue(type: .assertionFailure, compactDescription: "Invalid data") // Attach the invalid data. issue.add(XCTAttachment(data: data)) // Capture the call site location as the point of failure. let location = XCTSourceCodeLocation(filePath: file, lineNumber: line) issue.sourceCodeContext = XCTSourceCodeContext(location: location) // Record the issue. self.record(issue) } } -
11:12 - Override record(_ issue:) for observation
override func record(_ issue: XCTIssue) { // Observe, introspect, log, etc.: if shouldLog(issue) { print("I just observed an issue!") } // Don't forget to call super! super.record(issue) } -
11:30 - Override record(_ issue:) to suppress failures
override func record(_ issue: XCTIssue) { // If you don't want to record it, just return. if shouldSuppress(issue) { return } // Otherwise pass it to super. super.record(issue) } -
11:39 - Override record(_ issue:) to add an attachment
override func record(_ issue: XCTIssue) { // Redeclare using var to enable mutation. var issue = issue // Add a simple attachment. issue.add(XCTAttachment(string: "hello")) // Pass it to super. super.record(issue) }
-