[英]Swift UI tests - XCTAssertEqual has the wrong behaviour
I'm currently trying to do some tests in my iOS application but I'm facing a problem. 我目前正在尝试在iOS应用程序中进行一些测试,但遇到了问题。
Here is my code (I will explain the issue right after) : 这是我的代码(我将在稍后解释问题):
let passwordField = app.secureTextFields["Password"]
passwordField.tap()
passwordField.typeText("Password")
let password = passwordField.value as? String
guard let testPassword = password, !testPassword.isEmpty else {
XCTFail("Authentication tests failed : password field is wrongly formatted.")
return
}
XCTAssertNotEqual(password, "Random password")
XCTAssertEqual(password, "Password")
The XCTAssertNotEqual part is good, but the XCTAssertEqual isn't. XCTAssertNotEqual部分不错,但XCTAssertEqual不好。 Here is the error :
这是错误:
XCTAssertEqual failed : (“Optional(“********”)”) is not equal to (“Optional(“Password”)”)
Does anyone have an idea why does it throw this error ? 有谁知道为什么会引发此错误? I guess that I have to "play" with the fact that this is a secure text but I didn't find any answer yet.
我想我必须“玩弄”这是一个安全的文本,但是我还没有找到任何答案。
Thank you for your help. 谢谢您的帮助。
There is nothing wrong with XCTAssertEqual
. XCTAssertEqual
没有错。
The first statement 第一句话
XCTAssertNotEqual(password, "Random password")
is right, because: 是正确的,因为:
`*********` is not equal "Random password"
The second one fails because of the error message you see in the console. 由于您在控制台中看到的错误消息,第二个失败。
Personally, I think your logic for testing here is a bit messed up. 就个人而言,我认为您在此处进行测试的逻辑有些混乱。 First of all, i think there is no interface for
XCUIElement
to reverse the secure text to normal text. 首先,我认为
XCUIElement
没有将安全文本还原为普通文本的接口。
Second, why would you like to verify, what is in the textField
? 其次,为什么要验证
textField
? It will be for sure, whatever you type in there, there is no point to test a native iOS UI element very basic functionality. 可以肯定的是,无论您在此处键入什么内容,都没有必要测试本机iOS UI元素的非常基本的功能。
If you would like to test the authentication, than try to sign in with an incorrect password, and than with a correct one, and test the responses from you BE 如果您想测试身份验证,则尝试使用错误的密码登录,然后尝试使用正确的密码登录,然后测试您的响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.