2

I'm facing an issue which I can't manage how to workaround it.

I'm trying to stub the requests from my app - which uses Alamofire - to the API server, but nothing seems to avoid the server hit.

My test case:

func testNotificationsWhenLoggedIn() {
    let expectation = expectationWithDescription("Alamofire")

    self.api.notifications() { response in
        XCTAssertTrue(response.success)
        expectation.fulfill()
    }

    waitForExpectationsWithTimeout(5.0, handler: nil)
}

My self.api.notifications() method triggers a request to /api/notifications/ path on localhost host and I'm stubbing it as follows:

override func setUp() {
    super.setUp()
    stub(isPath("/api/notifications/")) { _ in
        let stubData = ["success":true]
        return OHHTTPStubsResponse(JSONObject: stubData, statusCode:200, headers:nil)
    }
}

My project has a test target, which uses my app target as Host Application.

I'm using:

  • Xcode 7.3
  • Swift 2.2

Not sure if I'm missing some setup/xcode trick here.

Igor Belo
  • 718
  • 6
  • 14

0 Answers0