Meituan Mini‑Program Testability Practices and Implementation
Meituan’s Tech Salon Session 77 describes how the company built a generic JavaScript‑hooking SDK packaged as an NPM module to give mini‑programs on platforms such as WeChat, Alipay and Kuaishou observable and controllable capabilities across UI, storage, network and system layers, enabling automated cache management, request mocking, state inspection and visual diff testing, which the ticket team leveraged to achieve over 30 % test scenario coverage, 100 % page coverage and discover hundreds of defects, while outlining future plans to stabilize and expand the framework.
This article, derived from Meituan Tech Salon Session 77, introduces the quality‑risk control and stability engineering practices for Meituan’s billion‑scale traffic system, focusing on mini‑program testability.
1. Introduction – Testing is modeled as an incentive‑response‑check loop. For mini‑programs, the incentive is a test action, the response is the program’s behavior, and the check validates the outcome. Challenges include limited observability of internal state, reliance on host apps (WeChat, Kuaishou, Baidu, etc.), and difficulty injecting test hooks.
2. Mini‑Program Testability Overview – Meituan built a generic testability SDK that provides observable and controllable capabilities across UI, storage, network, and system layers. The SDK is packaged as an NPM module and can be integrated into any mini‑program without additional adaptation.
2.1 Usage and Effects – The SDK is used via the Lyrebird test workbench, which offers cache management, page navigation, network request mocking, login state control, and visual diff testing. Manual testing examples include cache verification and direct page jumps.
2.2 Integration – Developers import the SDK NPM package into the mini‑program source or build output. An adapter layer extends support to multiple host platforms (WeChat, Alipay, Kuaishou, Baidu) by adjusting API calls and syntax.
2.3 Implementation Principles – The core technique is JavaScript Hooking. Three hook types are used:
Function Hook:
let _originAlert = alert;
alert = function () {
console.log('alert start');
_originAlert.apply(this, arguments);
console.log('alert end');
};Object Property Hook (e.g., cookie):
Object.defineProperty(document, 'cookie', {
set: function (val) {
console.log('set cookie:', val);
currentCookie = val;
return val;
},
get: function () {
return null;
}
});Proxy Hook:
let handler = {
get(target, prop) {
console.log(`Getting ${prop}`);
return target[prop];
},
set(target, prop, val) {
console.log(`Setting ${prop} to ${val}`);
target[prop] = val;
return true;
}
};
let proxy = new Proxy(window, handler);
proxy.test = 'test';
console.log(proxy.test);Static Hook modifies source files during build.
The SDK architecture consists of four layers: Communication, Command Dispatch, Function, and Hook. The Hook layer intercepts core APIs (e.g., wx.request) to enable request proxying, cache control, and state observation.
Example of wx.request Hook:
// Save original request
let _originRequest = wx.request;
// Override with hook
wx.request = function (options) {
// modify options, e.g., change URL, add headers
console.log('Hooked request:', options);
return _originRequest.call(this, options);
};3. Meituan Ticket Business Mini‑Program Test Practice – The ticket team uses the SDK to automate cache‑driven scenarios such as preserving form data across page navigation. By controlling cache reads/writes through the SDK, they achieve deterministic UI states and reduce manual steps.
Key outcomes: >30% of test scenarios rely on testability features, >100 automated test cases achieve 100% page coverage and 80%+ scenario coverage, and hundreds of defects have been discovered.
4. Summary & Outlook – Since 2021, Meituan’s in‑store R&D platform has systematically built mini‑program testability, integrating it into the full testing toolchain. Future work will focus on stabilizing core capabilities and extending them to more business‑specific needs.
Q&A – Addresses common concerns about proxy bugs, SDK transparency, integration effort, performance impact, and applicability limits (e.g., host‑app internals, backend‑only testing).
Meituan Technology Team
Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
