有问题的UITest启动应用程序,点击一个单元以推动要测试的屏幕,然后在我进行更改时失败并出现fatalError(),我希望该更改将调用fatalError()。
我如何在UITest上捕获fatalError并使用它报告UITest失败?
这里是UITest:
class ConcreteFoodScreenUITests: XCTestCase
{
let app = XCUIApplication()
override func setUpWithError() throws {
continueAfterFailure = false
app.launch()
}
func testPathToConcreteFoodScreen() throws {
//Tap Concrete Cell in FoodDashboard to go to the ConcreteFoodScreen
XCTAssertTrue(app.otherElements["FoodDashboard"].exists)
app.scrollViews.otherElements.tables.staticTexts["100 g, 100cal, P: 90g, F: 80g, C: 70g"].tap()
//ConcreteFoodScreen
XCTAssertTrue(app.otherElements["ConcreteFoodScreen"].exists)
app.tables.cells.containing(.staticText, identifier:"Scale").children(matching: .textField).element.tap()
app.keys["5"].tap() //FIXME: Crashes with a Fatal Error
}
}
这里是我想了解的正在触发的代码:
class ScaleCellTextField: SWDecimalTextField {
//there is more code here but not relevant
func updateFoodEntry() {
fatalError()
// if let scale = Double(self.text!) {
// concreteFood.scale = scale
// }
}
}
您可以看到我在这里注释了一些代码以使其正常工作。
恐怕你不能。 FatalError()
结束了您应用的流程,所以我不确定您是否可以捕获此类事件。