Xctest VC层次结构没有Xcuitest?
我想在不使用Xcuitest的情况下测试一个ViewController层次结构,因为它们的吨比普通的Xctest长。
我取得了一些成功,但我似乎无法创建一个多个级别的ViewController层次结构。
这是一个证明问题的测试案例:
class VCHierarchyTests: XCTestCase {
func test_CanMakeViewControllerHierarchy() {
let baseVC = UIViewController()
let vcToPresent = UIViewController()
let vcOnTopOfThat = UIViewController()
let vcOnTopOfThatOnTopOfThat = UIViewController()
newKeyWindowWith(root: baseVC)
baseVC.present(vcToPresent, animated: false)
vcToPresent.present(vcOnTopOfThat, animated: false)
vcOnTopOfThat.present(vcOnTopOfThatOnTopOfThat, animated: false)
//this passes:
XCTAssertNotNil(baseVC.presentedViewController)
//this fails:
XCTAssertNotNil(vcToPresent.presentedViewController)
//this fails:
XCTAssertNotNil(vcOnTopOfThat.presentedViewController)
}
private func newKeyWindowWith(root viewController: UIViewController){
let window = UIWindow(frame: UIScreen.main.bounds)
window.makeKeyAndVisible()
window.rootViewController = viewController
}
}
有没有办法在没有Xcuitest的情况下构建ViewController层次结构?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 view controllererPresentationspypy
它旨在拦截单个
present()
调用,而不是其中几个。如果您的用例不在其所做的事情之外,请提出问题。Try
PresentationVerifier
from ViewControllerPresentationSpy to unit test how view controllers are presented.It's designed to intercept a single
present()
call, not several of them. If your use case falls outside what it does, please file an Issue.