1

I want to know is there any way to redirect/swizzle all my iOS app api request to my mock server (local server) for XCUITesting. What i want to achieve is, instead of doing http://localhost:8080/request, i want to redirect my actual request http://www.test.com/request to http://localhost:8080/request.

Reegan
  • 11
  • 1

1 Answers1

0

If you’re running the ‘XCUITest’ locally, you could use a proxy tool such as CharlesProxy to redirect requests to your local server. This approach may work fine if you’re just developing and testing on your machine, but it doesn’t tend to work in CI or on a remote server.

Another option is to pass a launch argument to your app before XCUITestCase launches it. In the app, you can check if the argument was passed, and if so, could use the local host base URL. This has he advantage that it could be done remotely under automation. See this SO answer for details.

Gniem
  • 111
  • 4
  • Thanks. We ended up swizzling URLSession and wrote custom json to run it as server within the app. – Reegan Aug 12 '19 at 14:27