【问题标题】:Asynchronous Swift Testing of Protocols with XCTestCase使用 XCTestCase 对协议进行异步 Swift 测试
【发布时间】:2014-12-23 00:02:06
【问题描述】:

我正在尝试快速编写一个 REST Api 类并对其进行测试。我试图遵循how to test asynchronous methods Swift 中的方法,但我似乎遇到了问题。

客户端/RestInterface.swift

import Foundation


protocol RestSearchProtocol {
    func didRecieveResponse(results: NSDictionary)
}


public class RestInterface : NSObject {
    // lots of code we don't care about ...
}

ClientTests/RestInterfaceTests.swift

import UIKit
import XCTest
import Client

class RestInterfaceTests: XCTestCase, RestSearchProtocol {
// ... rest of the test file

我收到一个未声明的类型错误。

关于如何完成这项工作的任何建议?

附带说明 - 如果我采用 RestInterfaceTests 类并将其放在 RestInterface.swift 的末尾,它似乎找到了协议,但是 XCTestCase 现在未声明

【问题讨论】:

    标签: unit-testing swift xcode6


    【解决方案1】:

    看来我缺少 public 标识符:

    import Foundation
    
    
    public protocol RestSearchProtocol {
        func didRecieveResponse(results: NSDictionary)
    }
    
    
    public class RestInterface : NSObject {
        // lots of code we don't care about ...
    }
    

    已经解决了问题

    【讨论】:

      【解决方案2】:

      使用 @testable import Client 您不再需要将您的类型设置为公开!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-02
        • 2013-06-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多