/ddmock-ios

Primary LanguageSwiftMIT LicenseMIT

Deloitte Digital

DDMockiOS

An API mocking library for iOS.

CI Status Version License Platform

Requirements

Installation

CocoaPods

DDMockiOS is available through CocoaPods.

  1. Add the following line to your Podfile:
pod 'DDMockiOS'
  1. Run pod install

  2. 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"

  1. Follow Getting Started steps

Building from scratch

  1. Run sh build-xcframework.sh

  2. Framework should be added in output/DDMockiOS

  3. Drag output/DDMockiOS/ into project root folder

  4. Create a new run script in the target build phase and add

python "${SRCROOT}/DDMockiOS/init-mocks.py" "<path_to_mock_files_directory>/mockfiles"

  1. Follow Getting Started steps

Getting started

  1. Add DDMock.shared.initialise() to AppDelegate

  2. Add DDMockProtocol.initialise(config: ...) to networking library

e.g.

let configuration = URLSessionConfiguration.default
// other configuration set up
DDMockProtocol.initialise(config: configuration)
  1. Check if after first run of the app, the Settings.bundle file underneath the DDMockiOS/ is added to the project. If not add this to the project.

Mock API files

  • 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

License

DDMockiOS is available under the MIT license. See the LICENSE file for more info.