简体   繁体   English

如何在Swift中使用XCAssert检查isViewLoaded?

[英]How can I check isViewLoaded using an XCAssert in Swift?

I'm writing XCUITests and I'd like to check if my ViewController has loaded. 我正在编写XCUITests,我想检查是否已加载ViewController。 I'm thinking thinking to access the isViewLoaded Bool property. 我在考虑访问isViewLoaded Bool属性。 How would that look as an assertion? 看起来如何断言?

func XCTAssert(isViewLoaded == true, "MyViewController view loaded successfully")

The above code gives me an error. 上面的代码给我一个错误。 How would it look? 看起来如何?

You have to call isViewLoaded on an actual instance of a view controller. 您必须在视图控制器的实际实例上调用isViewLoaded And the message you provide should indicate that the assertion failed, not succeeded. 并且您提供的消息应表明断言失败而不是成功。

let vc = ... // some view controller

XCTAssert(vc.isViewLoaded, "MyViewController view failed to load")

The first parameter is what you want to happen - your expectation. 第一个参数是您想要发生的事情-您的期望。 The second parameter is the message that is used when an assertion FAILS. 第二个参数是断言失败时使用的消息。 So you have to do it like this: 因此,您必须这样做:

let viewController = UIViewController()
XCTAssertTrue(viewController.isViewLoaded, "viewcontroller's view failed loading")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Swift 4 检查是否启用了“请勿打扰模式” - How can I check if "Do not Disturb mode" is enabled using Swift 4 如何在 Swift 4 中检查上一个视图控制器 - How can I check Previous View Controller in Swift 4 如何检查Swift 4.0中是否有正则表达式的连续字符? - How can I check is there any consecutive characters with a regex in Swift 4.0? swift-如何检查特定的viewController是否为先前的viewController - swift - how can i check if a specific viewController is the previous viewController 如何检查数组中的句子在Swift中是否包含确切的单词? - How can I check if sentences in array contains exact words in Swift? 如何在Swift中检查实例的类型? - How can I check an instance's type in Swift? AWS Cognito Swift SDK如何检查用户是否已确认? - AWS Cognito Swift SDK How can I check if a user is confirmed? 我如何通过Swift检查我在prepareForSegue函数内部为TableViewController单击的部分? - How can i check that which section that i clicked for TableViewController inside of prepareForSegue function by Swift? Swift 如何检查是否遍历 List[String] 的最后一项 - Swift how can i check if i iterate through the last item of List[String] 如何检查数组中有多少个元素并将它们中的每个元素分配给 Swift 中的一个标签? - How can I check how many itens I have in an array and assign each one of them to a label in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM