【问题标题】:Detect if Test Failed in tearDown() Function - Xcode UIAutomation, XCTest, Swift检测 tearDown() 函数中的测试是否失败 - Xcode UIAutomation、XCTest、Swift
【发布时间】:2016-02-26 21:00:12
【问题描述】:

如果测试通过,我想更新一些日志,如果测试通过,我会更新一些不同的日志。在 tearDown() 方法中如何确定测试是通过还是失败?

override func tearDown() {
    super.tearDown()
    // Would like an if statement here to update my logs but not sure how to detect the state
    if fail {
        log.update("failed")
    } else if !fail {
        log.update("success")
    }

}

【问题讨论】:

  • 在同一张纸条上,有没有办法检测它是否是最后一次测试?

标签: xcode swift xctest xcode-ui-testing


【解决方案1】:

如果测试失败,testRun?.failureCount 应该大于 0:

override func tearDown() {
    super.tearDown()

    if testRun?.failureCount > 0 {
        log.update("failed")
    } else {
        log.update("success")
    }

}

判断这次拆解是否是最后一次拆解有点困难,但在最后一次测试后运行拆解的简单方法是:

override class func tearDown() {
    super.tearDown

    // Do Something after all tests have ran
}

【讨论】:

  • If 语句还应该检查unexpectedExceptionCount 是否大于零。
  • totalFailureCount 捕获所有失败和异常
猜你喜欢
  • 2013-10-23
  • 1970-01-01
  • 2016-07-05
  • 2015-06-14
  • 2013-08-30
  • 2016-11-13
  • 1970-01-01
  • 2018-05-09
相关资源
最近更新 更多