Swift2 XCTASSERTEQUAL在UTTest上失败
我在写作测试方面是新手。我试图为标题为“0”的按钮编写一个测试,点击后,其标题必须更改为“1”。测试功能如下:Swift2 XCTASSERTEQUAL在UTTest上失败,swift2,xctest,xcode-ui-testing,xcode7.3,Swift2,Xctest,Xcode Ui Testing,Xcode7.3,我在写作测试方面是新手。我试图为标题为“0”的按钮编写一个测试,点击后,其标题必须更改为“1”。测试功能如下: func testTapNumberButtonIncrementsScore() { XCUIApplication().buttons["0"].tap() let newScore = XCUIApplication().buttons["1"].label XCTAssertEqual(newScore, "1") } 在与“newScore”联机时,
func testTapNumberButtonIncrementsScore() {
XCUIApplication().buttons["0"].tap()
let newScore = XCUIApplication().buttons["1"].label
XCTAssertEqual(newScore, "1")
}
在与“newScore”联机时,我收到一条错误消息,指出“UI测试失败-未找到“1”按钮的匹配项”
似乎按钮的标题在点击时并没有改变。我已经改变了按钮的标题,当按钮被点击在这个按钮的@iAction。但是,如果我将断点与“newScore”保持一致,然后等待某个时间并继续;测试成功。您必须等待标签为“1”的按钮
您必须等待标签为“1”的按钮
XCUIApplication().buttons["0"].tap()
let newScoreButton = XCUIApplication().buttons["1"]
let exists = NSPredicate(format: "exists == 1 || enabled == 1")
expectation(for: exists, evaluatedWith: newScoreButton, handler: nil)
waitForExpectations(timeout: 50) { error in
if error != nil {
assertionFailure("The newScoreButton doesn't exists.")
}
}
newScore = newScoreButton.label
XCTAssertEqual(newScore, "1")