2016-12-13 20 views
0

필자는 테스트에서 새로운 것입니다. 나는 제목 "0"으로 도청 된 버튼에 대한 테스트를 작성하려고 시도하고 도청 후 제목은 "1"로 변경해야합니다. 테스트 기능은 다음과 같습니다 :UTTest에서 XCTAsssertEqual이 실패했습니다.

내가 "UI 테스트 실패 - 일치하는 항목이 발견되지"라는 오류 'newScore'와 라인
func testTapNumberButtonIncrementsScore() { 
    XCUIApplication().buttons["0"].tap() 
    let newScore = XCUIApplication().buttons["1"].label 
    XCTAssertEqual(newScore, "1") 
} 

1 "버튼"

이 버튼의 제목에 변경되지 않습니다 보인다 꼭지. 이 버튼의 @IBAction에서 버튼을 탭하면 버튼의 제목을 변경했습니다. 그러나 'newScore'라는 줄에 중단 점을 유지하고 언젠가는 기다렸다가 계속하면; 테스트 성공.

답변

2

라벨이 "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")