An API mocking library for iOS.
DDMockiOS is available through CocoaPods.
- Add the following line to your Podfile:
pod 'DDMockiOS'
-
Run
pod install
-
Create a new run script in the target build phase and add
python "${PODS_ROOT}/DDMockiOS/init-mocks.py" "<path_to_mock_files_directory>/mockfiles"
- Follow Getting Started steps
-
Run
sh build-xcframework.sh
-
Framework should be added in
output/DDMockiOS
-
Drag
output/DDMockiOS/
into project root folder -
Create a new run script in the target build phase and add
python "${SRCROOT}/DDMockiOS/init-mocks.py" "<path_to_mock_files_directory>/mockfiles"
- Follow Getting Started steps
-
Add
DDMock.shared.initialise()
to AppDelegate -
Add
DDMockProtocol.initialise(config: ...)
to networking library
e.g.
let configuration = URLSessionConfiguration.default
// other configuration set up
DDMockProtocol.initialise(config: configuration)
- Check if after first run of the app, the
Settings.bundle
file underneath theDDMockiOS/
is added to the project. If not add this to the project.
- All API mock files must be stored under a directory called /mockfiles.
- The /mockfiles must be a folder reference and not a group and stored under the Resources folder
- All API mock files are mapped based on the endpoint path and HTTP method.
- e.g. login mock response file for endpoint POST BASE_URL/mobile-api/v1/auth/login should be stored under mobile-api/v1/auth/login/post
- For dynamic endpoint url, create directories with _ and _ for every replacement blocks and parameters
- e.g. mock files for GET BASE_URL/mobile-api/v1/users/_usersId_ should be stored under mobile-api/v1/users/{usersId}/get
- see
sample
- All mock files need to be JSON files
- There can be more than one mock file stored under each endpoint path
- By default, the first file listed (alphabetically ordered) under each endpoint path is selected as the mock response
DDMockiOS is available under the MIT license. See the LICENSE file for more info.