Have you ever tried to mock web server in Xcode UI Tests? Fibs is the simplest way to do this - completely separated from Xcode project. It is a server running locally that serves endpoint that allows you mocking other endpoints!
Fibs has 2 main features:
- Mocking endpoints with any attributtes
- Executing shell commands locally on running machine
Run the application before starting UI tests with ./Pods/Fibs/fibs
If you would like to mock endpoint you need to hit localhost:8080/mock
route (from UITest target), example cURL:
curl -v\
-X POST\
-H "Content-Type: application/json"\
-H "Accept: application/json"\
-d "{ \"headers\": { \"X-Custom-Header\" : \"X-Custom-Value\" }, \"method\": \"GET\", \"path\": \"/content/restaurant/([0-9]$)\", \"body\": { \"id\" : \"1\"} }"\
"localhost:8080/mock"
where body represents endpoint details. All possible attributes that can be mocked are listed below:
method
- HTTP request method, with possible values of: "GET", "POST", "PUT", "DELETE", "PATCH"path
- endpoint path that supports regular expression, example: "/content/restaurant/([0-9]$)"code
- HTTP response status codebody
- HTTP response, can be any valueheaders
- HTTP response headers which is jsondelay
- time interval in miliseconds that (integer) that response will be delayed
Fibs gives you also ability to run any shell command on macOS from UI test target.
This could be useful for running special mocking scripts that modifies your tested system.
To run shell command hit localhost:8080/command
, example cURL:
curl -v\
-X POST\
-H "Content-Type: application/json"\
-H "Accept: application/json"\
-d "{ \"command\": \"echo 'Hello World'\"}"\
"localhost:8080/command"
Parameters of such call are:
command
- raw string command that you want to run on hosting system
Also, response for this request is synchronous, which means you can later process it back in UITests target. For the request above, the response would be:
{"raw_response":"Hello World"}
pod 'Fibs'
TODO