FireMock

FireMock help to stub HTTP requests. If you are looking for an easy way to test your request or work with your server which is not ready so you are in a good place. Test your apps with fake response data and files with a short effort.
With a short code you can set multiple mock and switch from them on runtime with a custom view provide by FireMock.

Swift4 Only

Enable FireMock

Add this code in your application to enable FireMock.

FireMock.enabled(true)

Implement FireMockProtocol

For each request you can associate a mock that will be used to return the desired response. Creating a mock is very simple. Implement the FireMockProtocol protocol and define its characteristics. All are optional except the mockFile function that expects the file to be used when the request is started.

For example if you have a service to fetch news with multiple possible responses :

Register

Last step, register one or more mocks for specific request. Specify for which url it is associated and if it is enabled.
You can disable during compilation and enable it on runtime. You can also change the mock during runtime. This is described below.

Host Condition

You can use your mock files with specific hosts only. If empty, mock works for all hosts.

FireMock.onlyHosts = ["foo.com"]

You can exclude hosts.

FireMock.excludeHosts = ["foo.com"]

Debug

Debug information about requests intercepted and enable or disable mocks. You can set 2 different levels information.

FireMock.debug(enabled: true)

Enable and Change Mock on runtime

All mocks can be enable or not on runtime. FireMock provide a ViewController that list all mocks registers by you. So it becomes easy to switch from one state to another without having to change code. You can also change the mock during runtime if you have registers 2 or more.

FireMock.presentMockRegisters(from: self, backTapped: nil)

Integrate with 3rd Party

FireMock handle automatically integration with 3rd Party network when it used URLSession API. FireMock uses Swizzling method to add FireURLProtocol in protocolClasses array from session configuration.