Questions tagged [ohhttpstubs]

iOS open source library used to tests apps with fake network data and custom response time, response code and headers

OHHTTPStubs is a library designed to stub your network requests very easily. It can help you:

  • test your apps with fake network data (stubbed from file) and simulate slow networks, to check your application behavior in bad network conditions
  • write unit tests that use fake network data from your fixtures. It works with NSURLConnection, NSURLSession, AFNetworking, Alamofire or any networking framework that use Cocoa's URL Loading System.
19 questions
6
votes
2 answers

Test request body with OHHTTPStubs in Swift

I'm trying to test the request body sent captured with OHHTTPStubs but it seems buggy returning because the request.httpBody is nil. I found this info about this problem Testing for the request body in your stubs. But I'm pretty…
Addev
  • 31,819
  • 51
  • 183
  • 302
4
votes
1 answer

Cocoa Error 3840 on AFNetworking

I am writing a unit test case with AFNetworking 2.0 and OHHTTPStubs, and the test always failed with these errors: Response error:The operation couldn’t be completed. (Cocoa error 3840.). Thanks a lot! Below is the simple test Json (User.json): { …
3
votes
2 answers

OHHTTPStubs not stubbing host?

OHHTTPStubs not mocking requests if the iOS Application has it's own requests? If the App does any Alamofire request before the tests run, OHHTTPStubs will not mock any requests in unit tests OHHTTPStubs 4.3.0 with swift support Alamofire…
wyu
  • 1,793
  • 17
  • 33
3
votes
1 answer

How to test AFNetworking

*Edit - I originally wanted to test AFNetworking using Nocilla but ended up using OHHTTPStubs to do the job. I've answered the original question below, using OHHTTPStubs * Original Question: I want to test the APIClient of our app - the bare bones…
Octave1
  • 525
  • 4
  • 19
2
votes
0 answers

Stub network with OHHTTPstubs and Swift

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() { …
Igor Belo
  • 718
  • 6
  • 14
2
votes
3 answers

Getting Alamofire and OHHTTPStubsWorking together

I am trying to setup OHHTTPStubs to work with Alamofire for my unit tests but they always seem to load from the live network when using Alamofire. I have turned off using a host application in the test target and have made sure that OHHTTPStubs…
pixelrevision
  • 364
  • 3
  • 12
2
votes
1 answer

OHTTPS + AFNetworking Mocking the Failure Response

I am currently using OHTTPStub to mock the responses of my AFNetworking calls. The AFNetworking calls return either a successful response or a failing response. If I create a stub using "responseWithJSONObject" method, which is the only example…
Charlie Cliff
  • 109
  • 2
  • 4
1
vote
1 answer

OHHTTPStubs Unit Test Implementation

I am trying to correctly implement OHHTTPStubs but am having a bit of trouble. I want to do exactly what this library does. Make a request to a URL and return a mocked JSON response. This is how I have it set up, yet nothing ever gets called…
Michael
  • 193
  • 2
  • 12
1
vote
2 answers

Swift: Test implementation of OHHTTPStubs showing errors

I pull OHHTTPStubs via cocoa pods but I'm having some issues I can not figure out why. Here is a copy of my podFile # platform :ios, '11.3' target 'myApp' do use_frameworks! target 'myAppTests' do inherit! :search_paths pod…
user2924482
  • 8,380
  • 23
  • 89
  • 173
1
vote
2 answers

How to stub network requests on UITesting

Is there any way to stub network requests for UITests which are written in Swift? I’ve already installed OHHTTPStubs pods but couldn’t managed to stub my network requests via using its methods which is because UITest target and application target…
1
vote
0 answers

OHHTTPStubs with AFNetworking in Cedar

I am struggling to set up a simple stub of a network POST request. I have modeled as much as I can from the OHHTTPStubs docs and other resources online, but I think I must be missing something. I would like to see the stub called based on the…
Corbin
  • 152
  • 1
  • 10
1
vote
1 answer

Cannot test stub responses with Alamofire

I'm trying to test Alamofire request stubbing the responses using OHHTTPStubs and Quick/Nimble. However Alamofire doesn't process the response and consequently I cannot test the result. My current testing code…
1
vote
1 answer

"OHHTTPStubs/OHHTTPStubs.h" file not found

I have added lib OHHTTPStubs manually but it's showing error "OHHTTPStubs/OHHTTPStubs.h" file not found. Appreciate for help.
user4276168
1
vote
1 answer

iOS asynchronous unit test with Specta and OHHTTPStubs never fails (when it should!)

I'm attempting to unit test the networking code in my app, and I'm having a few issues where I want to see my test fail to ensure it's all working, before I go and get it all passing. The thing is, it's always passing. I'm using Xcode6-Beta7 in…
1
vote
1 answer

Can't get OHHTTPStubs to work with NSURLSession

I'm trying to use OHHTTPStubs in my XCTest class, This is how I configured OHTTPStubs in my test file. // // Tests Configuration // - (void)setUp { [super setUp]; _bundle = [NSBundle bundleForClass:[self class]]; [self…
Goles
  • 11,599
  • 22
  • 79
  • 140
1
2