AliSoftware / OHHTTPStubs

Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
MIT License
5.03k stars 601 forks source link

Is it possible to disable/log network calls if they are not mocked? #276

Closed szymon-kazmierczak closed 6 years ago

szymon-kazmierczak commented 6 years ago

New Issue Checklist

Environment

Issue Description

Is it possible to disable network calls if they are not mocked? I want to make sure that my test suite does not perform any network call that is not mocked - ideally log the cases where the mock is missing, with some additional info like URL.

In another project I'm working on (Android app, using RESTMock, the mocking solution has its own IP/port (localhost and an empty port) and it intercepts all the calls being made and notifies the user when a mock is missing.


 E/RESTMock: <- Response ERROR: NOT MOCKED: GET /api/settings/settings.json HTTP/1.1
                                            list of mocked requests:
                                           (HTTP method is: POST and url contains: /access/auth)
                                           (HTTP method is: GET and url starts with: /api/tickets.json) ```
AliSoftware commented 6 years ago

Hello

Yes it is totally possible.

Either by using a fallback stub, as explained in the wiki here

Or better, since the last version (6.1.0) there's even a dedicated method for that now, called onStubMissing. You can call it in the setup of your tests to tell what to do if a network request which is not subbed is encountered, so you can for example log a message, make your test fail, or fatalError, or make the request return an HTTP error for those unstubbed requests, etc.