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
We've developed an embedded HTTP server in pure Swift, you can run the HTTP server with simple mock response handler in your test case, then pass the URL to the target app via environment variable like API_BASE_URL
. I wrote an article about how to do it
Embedded web server for iOS UI testing
Basically there are two libraries, one is Embassy, it's the simple async HTTP server. Another one is Ambassador, a simple web framework for mocking API endpoints.
You could either mock them using OHHTTPStubs, or by writing your own stubs.
In a nutshell, you should stub requests with a NSURLSession subclass and inject the stubbed NSURLSession into your networking layer. The launchEnvironment property might be useful to pass mocked urls to the test.
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