[英]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.