【问题标题】:Use of unresolved identifier when testing a public class测试公共类时使用未解析的标识符
【发布时间】:2015-05-05 12:37:44
【问题描述】:

我无法对我的类进行单元化,因为 Xcode 没有看到我的主类在测试目标下。

我的 swift 模块被定义为 public

public class Geohash {
    public static func encodeGeoHash(latitude: Double, longitude: Double, precision: Int = 12) -> String {

但在我的测试目标下我看不到符号,

class GeohashTests: XCTestCase {
    func testEncode() {
        Geohash // /Users/maximveksler/Developer/GeohashKit/GeohashKitTests/GeohashTests.swift:13:9: Use of unresolved identifier 'Geohash'
    }
}

我的测试目标不包括 Geohash.swift

项目位于https://github.com/maximveksler/GeohashKit/blob/master/GeohashKitTests/GeohashTests.swift#L13

【问题讨论】:

    标签: swift geohashing


    【解决方案1】:

    在您的测试文件中添加以下行:

    import GeohashKit
    

    项目的测试部分是单独的模块,因此您需要导入您的应用模块来测试类文件才能访问其类。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 2016-07-17
    • 2016-04-29
    相关资源
    最近更新 更多