在单元测试的上下文中,直接调用委托方法是最合适的方法。您可以创建子类
WKNavigationAction,并将该类的实例作为输入参数传递给委托方法:
class FakeNavigationAction: WKNavigationAction { let testRequest: URLRequest override var request: URLRequest { return testRequest } init(testRequest: URLRequest) { self.testRequest = testRequest super.init() }}
稍后,在单元测试中:
// setupvar receivedPolicy: WKNavigationActionPolicy?let fakeAction = FakeNavigationAction(testRequest: ...)// actdelegateObject.webView(webView, decidePolicyFor: fakeAction, decisionHandler: { receivedPolicy =request})// assertXCTAssertEqual(receivedPolicy, theExpectedValue)
另一种方法是混淆的吸气剂
WKNavigationAction,因为这
C类,但是,这更像是一个骇人听闻的解决方案。是一个Objective-
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)