Mobile Development 7 min read

iOS Mocker: A Server‑Side Mock Service for Mobile Development at JD

The article introduces JD’s iOS Mocker, a server‑side mock service that decouples client development from backend progress, provides comprehensive mock data for all shopping‑flow interfaces, improves testing efficiency, ensures UI robustness, and outlines its architecture, usage workflow, and future extensions.

JD Retail Technology
JD Retail Technology
JD Retail Technology
iOS Mocker: A Server‑Side Mock Service for Mobile Development at JD

JD's core shopping flow is critical, and each version of the app receives numerous customized requirements. To maintain code quality and development efficiency, the team needed a tool to decouple client development from server progress and to manage test data effectively.

iOS Mocker is a server‑side interface mock tool used during iOS development for decoupling, test data preservation and sharing, and client fault‑tolerance testing. It currently supports core shopping modules such as search, product details, and cart, covering virtually all possible server response scenarios.

The development process traditionally required the client to wait for server endpoints to be ready, causing unnecessary delays and increasing post‑development workload. Additionally, the reuse mechanism of UI cells in list pages leads to many layout variations (over 200) that must be validated with special data sets.

Mocker aims to:

Eliminate client dependence on server progress by allowing developers to fetch predefined JSON data from the Mock server during development and self‑testing.

Provide comprehensive mock data that covers all test cases, enabling regression testing and code‑refactor verification.

Improve communication and efficiency between development and testing teams through shared Mock IDs.

Support client robustness and automated testing by allowing any field or data type to be altered without code changes.

The architecture consists of a Mock Server where developers upload or edit JSON data, generating a unique ID for each mock response. The client integrates Mocking at the network layer, intercepting requests via a custom NSURLProtocol subclass added through NSURLSessionConfiguration.protocolClasses . When a request matches a configured Mock ID, the original request is cancelled and the mock response is returned.

Key client behaviors include:

All interfaces respect the configured Mock ID and bypass pre‑release or production environments.

Multiple interfaces can be mocked simultaneously while others operate normally.

Mock configuration can be invoked from any page via a shake‑gesture UI, which can be disabled if it conflicts with other UI events.

Mocking code runs only in debug mode and has no impact on release builds.

Future plans involve integrating API documentation editing into the Mock Server and extending the concept of test data groups to further support agile development and automated testing.

Author: Jia Xiaobin, JD iOS Senior Engineer, responsible for search, promotion modules, tool development, and performance optimization.

Mobile DevelopmentiOStestingmockingAPIClient-Server
JD Retail Technology
Written by

JD Retail Technology

Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.