6
我想在我的Quick/Nimble BDD測試中做出Moya存根請求。 Moya有sampleData
參數我使用JSON文件中創建:BDY測試中的Moya存根請求
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存根請求?
謝謝!
我正在嘗試編寫一個測試,它檢查來自getPlaces請求的響應,但是以下兩個測試都成功響應此響應: 'testProvider.request(.getPlaces(地點: 「」)){在 地方希望(地方)。爲了(beNil()) }' 和 'testProvider.request(.getPlaces(地點: 「」)) {地點在 期望(地點).toNot(beNil()) }'。 爲什麼會發生這種情況?我做錯了什麼? – Svyatoslav
您是否使用stubClosure創建了測試提供程序?像這樣'let provider = RxMoyaProvider(stubClosure:MoyaProvider.immediatelyStub)' –
謝謝!此代碼適用於我。 – Svyatoslav