swift – BDD测试中的Moya存根请求

我想在 Quick/Nimble BDD测试中发出 Moya存根请求. Moya有一个我使用JSON文件创建的sampleData参数:

var sampleData: Data {
    switch self {
    case .getPlaces:
        // Provided that project have a file named get_places.json in it's bundle.
        guard let path = Bundle.main.path(forResource: "get_places", ofType: "json"),
            let data = Data(base64Encoded: path) else {
                return Data()
        }
        return data
    case .getPlaceDetail:
        // Provided that project have a file named get_place_detail.json in it's bundle.
        guard let path = Bundle.main.path(forResource: "get_place_detail", ofType: "json"),
            let data = Data(base64Encoded: path) else {
                return Data()
        }
        return data
    }
}

如何在测试中使用此参数?有什么想法在测试中发出Moya存根请求?

谢谢!

只需像在实际代码中那样使用您的提供商. Moya检测到当前目标是测试目标,并将返回样本数据而不是执行请求
相关文章
相关标签/搜索