如何在 XCTest 中对私有结构而不是结构的私有方法进行单元测试?

问题描述 投票:0回答:0

这里是一些示例代码。我怎样才能在 XCTest 中访问它?

private struct Thing {
    let name:String
    let age:Int
    
    init(name:String,age:Int) {
        self.name = name
        self.age = age
    }
}

我试过这样的事情

#if DEBUG
private struct Thing {
#else
struct Thing {
#end
    let name:String
    let age:Int
    
    init(name:String,age:Int) {
        self.name = name
        self.age = age
    }
}

当然不能编译。

swift xctest
© www.soinside.com 2019 - 2024. All rights reserved.