Mini programs are a major source of user traffic. To prevent performance bottlenecks from impacting the user experience, you must conduct stress testing before you launch new features. This ensures that your system remains stable even during unexpected traffic surges.
Common mini program stress testing scenarios
-
Evaluate the performance of new systems or features before launch to ensure stable operation.
-
Use stress testing to measure performance differences after performing system optimizations or scaling.
-
Assess system performance before anticipated traffic surges, such as marketing campaigns, to prevent crashes that could impact the user experience.
Advantages of PTS for mini program stress testing
-
PTS features a custom-built testing engine that supports TPS mode to accurately simulate traffic funnel models.
-
Initiates stress tests from regions across the Chinese mainland to simulate a realistic user distribution.
-
The built-in diagnostics tool shows error details down to the method stack level to help you pinpoint performance issues.
-
Supports client-side proxy recording, which significantly reduces script creation effort.
Start mini program stress testing
Unlike stress testing self-hosted websites, testing a mini program requires obtaining a token from the host platform, such as WeChat or Alipay. To successfully test your mini program's business APIs, you must use this token while it is valid. We recommend the following two methods for obtaining platform-authorized tokens:
-
(Recommended) Write an API to automatically obtain and refresh the token. In your test scenario, PTS calls this API to automatically retrieve a valid token.
-
Record platform tokens before the test and pass them as parameters to your mini program's business API. Note that the test duration must not exceed the token's validity period to avoid test failures due to token expiration.
This topic uses the WeChat platform as an example to show how to stress test a mini program.
Method 1: Via custom API
For example, to stress test a mini program's event page on the WeChat platform, you can write an API to retrieve the WeChat token. Then, in your test scenario, include this API, extract the token as an output parameter, and pass it to the subsequent business API.
-
In your local environment, write an API that can continuously retrieve WeChat tokens throughout the stress test.
-
Log on to the PTS console, choose , and then click PTS.
-
Enter a scenario name, for example,
myAPP. On the Scenario Configuration tab, click the arrow next to the API name to expand the settings. Then, fill in the details for the first API: the custom API for retrieving the WeChat token. -
Select the Output Parameter Definition tab and configure the parameters as shown in the following example:
-
Output Parameter Name: access_token
-
Source: Body: JSON
-
Parsing Expression: access_token

-
-
Click Add API, configure the second API, which is the mini program's event page API, and set the request method to POST.
-
At the bottom of the page, click Parameter List. In the dialog box that appears, click the copy icon next to the output parameter name to copy the output parameter reference.

-
To pass the copied
access_tokenoutput parameter in the API body, click the API's Body Definition tab. In the Key field, enter a custom name, such asinput_token, and in the Value field, paste the copied parameter reference.
-
In the Stress Mode Configuration section, specify the number of virtual users, test duration, and other settings based on your requirements.
Note-
To obtain logged-in WeChat user information, such as an OpenID or token, for use across sequential API operations, see Use cookies to simulate logons.
-
For more information about stress mode configuration, see Stress modes and configurations.
-
-
Click Save and Start. On the Note page, select Execute Now, select the The test is permitted and complies with the applicable laws and regulations. check box, and then click Start Test.
Method 2: Via data file
For example, to stress test a mini program's event page on the WeChat platform, you can batch-obtain platform tokens in advance or prepare local data if your business logic allows. You can then place this data in a file and use it as a global parameter during the test.
Platform tokens typically have a limited validity period and must be refreshed regularly. If you use this method, ensure the token's validity period exceeds your planned test duration. Otherwise, the test will fail when the tokens expire.
-
Create a
token.csvfile (you can create this by saving an Excel file as a .csv file or by using a library like Apache Commons CSV) and add the tokens in a single column. The following is an example:token T7MeDnBIMKRJdgUB8RNQixyhUPJPaJEG cqKscgeNWFPkkkaR4dBfcD4A2pD1CYFK eh3lbjmsjd9jh65xSwvBWvDtmky25CK9NoteYou can batch-obtain platform tokens from your online environment or, if your business logic permits, construct token data locally.
-
Log on to the PTS console, choose , and then click PTS.
-
Enter a scenario name, for example,
myAPP. On the Scenario Configuration tab, configure the API for the mini program's event page. -
Click Data Sources, and on the Files tab, click +Upload File to upload your local
token.csvfile. After the upload is complete, select Use First Line as Parameter Name. This treats the first row as a header, using it for the parameter name instead of as a data value. -
Next to the API name, hover over the
icon and select Add Parameter. -
Click the arrow next to Data Configuration to expand the settings. On the Data Source Parameters tab, select the Parameter Name. Click the copy icon to copy the parameter reference.
-
To pass the copied parameter in the API body, click the Body Definition tab for the event page API. In the Key field, enter a custom name such as
token, and in the Value field, paste the copied parameter reference.
-
In the Stress Mode Configuration section, specify the number of virtual users, test duration, and other settings based on your requirements.
-
Click Save and Start. On the Note page, select Execute Now, select the The test is permitted and complies with the applicable laws and regulations. check box, and then click Start Test.