How do I mock network requests in Xcode UI tests while the tests are running?

前端 未结 3 603
天命终不由人
天命终不由人 2020-12-11 08:18

We\'ve got a suite of UI tests for our app written using KIF which I\'d like to convert to use the new Xcode UI test framework.

The app is a client of a Rest AI whos

3条回答
  •  清歌不尽
    2020-12-11 08:48

    We have been facing the exact same problem trying to migrate from KIF to UI Tests. To overcome the limitations of UI Tests with regards to stubbing and mocking we built a custom link between the app and the test code by using a web server that is instantiate on the app. The test code sends HTTP requests to the app that get conveniently translated to a stubbing request (OHHTPStub), a NSUserDefault update, upload/download an item to/from the app. It's even possible to start monitoring network calls when you need to check that specific end points get called. It should be fairly simple to add new functionalities should you feel there's something missing.

    Using the library is extremely simple, check it out on our github repo

提交回复
热议问题