私はそれを回避する方法を管理できない問題に直面しています。
Alamofire を使用するアプリから API サーバーへのリクエストをスタブしようとしていますが、サーバーのヒットを回避する方法はないようです。
私のテストケース:
func testNotificationsWhenLoggedIn() {
let expectation = expectationWithDescription("Alamofire")
self.api.notifications() { response in
XCTAssertTrue(response.success)
expectation.fulfill()
}
waitForExpectationsWithTimeout(5.0, handler: nil)
}
私のメソッドは、localhost ホストのパスへself.api.notifications()
のリクエストをトリガーし、次のようにスタブしています。/api/notifications/
override func setUp() {
super.setUp()
stub(isPath("/api/notifications/")) { _ in
let stubData = ["success":true]
return OHHTTPStubsResponse(JSONObject: stubData, statusCode:200, headers:nil)
}
}
私のプロジェクトには、私のアプリ ターゲットをホスト アプリケーションとして使用するテスト ターゲットがあります。
私は使用しています:
- Xcode 7.3
- スイフト 2.2
ここでセットアップ/xcodeのトリックが欠けているかどうかはわかりません。