我一直在为我的应用程序编写测试。但是,当运行我的测试时,我的函数上不断收到错误 Stall on main thread
private func waitForElementToAppear(testCase: XCTestCase,
element: XCUIElement,
file: String = #file,
line: UInt = #line) {
let existsPredicate = NSPredicate(format: "exists == true")
testCase.expectationForPredicate(existsPredicate,
evaluatedWithObject: element, handler: nil)
testCase.waitForExpectationsWithTimeout(5) { (error) -> Void in
if (error != nil) {
let message = "Failed to find \(element) after 5 seconds."
testCase.recordFailureWithDescription(message,
inFile: file, atLine: line, expected: true)
}
}
}
我在我的测试/代码中多次使用此函数。我怎样才能将其转换为辅助函数,这样我只需将该函数编写一次。提前感谢您的帮助:)
最佳答案
使用扩展更快捷:
extension XCTestCase {
// your function here
}
因此您可以在所有测试类中使用它,而无需额外的类
关于swift - 如何将私有(private)函数变成辅助函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41810608/