如何使用Swift和CocoaPods在iOS上对TwilioChatClient进行单元测试
由于Twilio Programmable Chat SDK非常复杂,我有时会遇到在应用程序中难以复制的场景,所以我决定做一些单元测试。 问题是,我无法初始化TwilioChatClient。你有什么想法我做错了吗?如何使用Swift和CocoaPods在iOS上对TwilioChatClient进行单元测试
的Xcode调试控制台
Test Case '-[ONNTests.ONNTests testTwoClientCreation]' started.     0x7000065c6000 | 12/18/13:26:18.979 | FATAL | Chat-iOS | Error instantiating client framework path. 
    0x7000065c6000 | 12/18/13:26:18.980 | DEBUG | Chat-iOS | releasing chat client instance: <TwilioChatClient: 0x7fcf01552c20> 
Podfile
target 'MyTests' do     pod 'TwilioChatClient', '~> 2.1.0' 
end 
代码
import XCTest import TwilioChatClient 
class MyTests: XCTestCase { 
    var client1: TwilioChatClient? 
    let e1 = XCTestExpectation(description: "Download Twilio token 1") 
    let e2 = XCTestExpectation(description: "Create client 1 successfully") 
    func testTwilioClientCreation() { 
     TwilioChatClient.setLogLevel(.debug) 
     getToken { [unowned self] token in 
      self.e1.fulfill() 
      TwilioChatClient.chatClient(withToken: token, properties: nil, delegate: self) { [unowned self] (result, client) in 
       if result.isSuccessful() { 
        self.client1 = client 
        self.e11.fulfill() 
       } 
      } 
     } 
     wait(for: [e1, e2], timeout: 20.0) 
    } 
    func getToken(completion: @escaping (_ token: String) -> Void) { 
     // ... 
    } 
} 
回答:
它看起来像Twilio ChatClient可以通过被测目标引入,而不是直接进入测试。这可能会导致我们查找框架中包含的资源的问题,这是您看到的消息。
要解决此问题,请确保TwilioChatClient框架直接声明为一个依赖于你的测试目标,例如:
target 'TestingSample' do     pod 'TwilioChatClient', '~> 2.1.0' 
    target 'TestingSampleTests' do 
    end 
end 
另外请注意,它是关机,当你用做客户端重要它可以在您的测试方法结束时或者在共享拆除方法中使用。
wait(for: [e1, e2], timeout: 20.0) self.client1?.shutdown() 
self.client1 = nil 
一个工作示例项目可以找到here。
我们将在未来的版本中使这一过程更加流畅,请让我们知道如果上述问题解决了您所看到的单元测试问题,或者我们可以进一步提供帮助。
以上是 如何使用Swift和CocoaPods在iOS上对TwilioChatClient进行单元测试 的全部内容, 来源链接: utcz.com/qa/263383.html
