【发布时间】:2022-01-09 14:57:33
【问题描述】:
我正在运行 UI 测试,我需要使用 waitForExpectations API 测试 Firebase 电话身份验证功能。目前我正在使用两个waitForExpectations,在第一个命令中工作正常,但在第二个命令中代码崩溃。
代码:-
func testsendOTPAndVerify() {
let expection = expectation(description: "OTP Send With Correct Number")
let signupClassMthd = SignupScreen(phoneNumber: .constant("9814012345"))
signupClassMthd.verify { response, verificationId in
XCTAssert(response == true)
if response {
expection.fulfill()
self.testVerifyOTP(verificationID: verificationId)
}
}
self.waitForExpectations(timeout: 30) { respoError in
if let errors = respoError {
print("OTP Send ",errors.localizedDescription)
}
}
}
func testVerifyOTP(verificationID:String){
let expection = expectation(description: "Check OTP")
let verfyClassTest = VerficationCode(phoneNumber: .constant(CommonAllString.BlankStr), verificationID: .constant(verificationID))
verfyClassTest.verifyPhoneNumberAndLogin(OtpEndrdCode: "000000") { response, responseBool in
if response == true && responseBool == false {
expection.fulfill()
}
XCTAssert(response == true && responseBool == false)
}
self.waitForExpectations(timeout: 30) { respoError in
if let errors = respoError {
print("Check OTP = ",errors.localizedDescription)
}
}
}
代码截图:-
错误:-
线程 1:“由于未捕获的异常 'NSInternalInconsistencyException' 导致应用程序终止,原因:'API 违规 - 在测试用例上调用等待而已经在等待。'”
【问题讨论】:
-
但这是 100% 明确的:“在等待时调用等待测试用例”
标签: swift firebase unit-testing firebase-authentication