Mini programs run on third-party platforms such as WeChat and Alipay, where API requests require platform-issued tokens that expire periodically. Most load testing tools do not natively handle token refresh, which can cause authentication failures during long-running tests. Performance Testing (PTS) solves this by supporting automatic token retrieval and refresh within test scenarios, so you can stress test your mini program's backend APIs without token expiration interrupting the test.
Common scenarios
Pre-release validation: Before you release a new system or feature, use stress testing to understand its performance baseline and ensure stable operation.
Post-optimization benchmarking: After you optimize or scale out a system, run stress tests to measure performance differences before and after the changes.
Traffic surge preparation: Before large-scale events or promotions that may cause traffic surges, evaluate system performance to prevent crashes that affect the user experience.
Choose a token-handling method
Before you set up a test, decide how PTS should handle platform tokens:
| Consideration | Method 1: Automatic retrieval (recommended) | Method 2: Pre-recorded CSV file |
|---|---|---|
| Test duration | Any duration | Must be shorter than the token validity period |
| Setup effort | Requires a custom token-retrieval endpoint | Requires collecting tokens manually |
| Token freshness | Always current -- PTS refreshes tokens automatically | Tokens may expire mid-test |
| Best for | Production-grade stress tests, long-running tests | Quick validation tests, short tests |
Prerequisites
Before you begin, make sure that you have:
An Alibaba Cloud account with PTS activated
A WeChat developer account with valid API credentials
A working backend API endpoint for your mini program
(Method 1 only) A custom API endpoint that retrieves and returns WeChat access tokens
(Method 2 only) A set of valid WeChat tokens saved in a CSV file
Method 1: Retrieve tokens automatically during the test
This method adds a token-retrieval API operation as the first step in your test scenario. PTS calls this operation before each business request, extracts the access_token from the response, and passes it to subsequent operations.
Workflow:
Build a token-retrieval API endpoint
Create a PTS scenario with two sequential API operations
Configure the first operation to output the access token
Configure the second operation to consume the token
Set load parameters and run the test
Step 1: Build a token-retrieval API endpoint
Create an API endpoint in your environment that calls the WeChat token API and returns the access token. Keep this endpoint available throughout the stress test so that PTS can retrieve fresh tokens continuously.
A typical response from your token endpoint:
{
"access_token": "T7MeDnBIMKRJdgUB8RNQixyhUPJPaJEG",
"expires_in": 7200
}PTS extracts the access_token field from this JSON response in Step 3.
Step 2: Create a PTS scenario
Log on to the PTS console.
Choose Performance Test > Create Scenario, and then click PTS.
Enter a scenario name, such as
myAPP.
Step 3: Configure the token-retrieval API operation
This is the first API operation in the scenario. It calls your custom token endpoint and extracts the access token from the response.
On the Scenario Settings tab, expand the first API operation and enter the URL and parameters of your token-retrieval endpoint.
Click the Output Parameter Definition tab and configure the following settings: PTS uses the parsing expression to locate the
access_tokenfield in the JSON response body shown in Step 1.Field Value Output Parameter Name access_token Source Body:JSON Parsing Expression access_token 
Step 4: Configure the business API operation
This is the second API operation. It sends requests to your mini program's activity page API and uses the token extracted in Step 3.
Click Add API to add a second API operation.
Enter the URL of your mini program's activity page API. Set the request method to POST.
Pass the access token to this API operation:
In the lower part of the page, click Parameters. In the Parameters panel, click Session Parameters.
Click the Copy icon next to the
access_tokenoutput parameter to copy the parameter reference.
Click the Body Definition tab of the second API operation. Enter a key name (for example,
input_token) in the Key field and paste the copied parameter reference in the Value field.
Step 5: Configure load parameters and run the test
In the Stress Mode Configuration section, configure load parameters based on your testing goals:
NoteFor guidance on choosing a stress testing model, see Configure the stress testing model and level.
Parameter Description Max VUs Maximum number of virtual users to simulate Total Test Duration How long the test runs Click Save and Start.
In the Note dialog box, set Execution Cycle to Execute Now, select the The test is permitted and complies with the applicable laws and regulations checkbox, and then click Start Test.
To pass WeChat logon information (such as OpenID and token) across multiple API operations in a single session, see Use cookies to simulate logons.
Method 2: Use pre-recorded tokens from a CSV file
If your tokens remain valid for the full test duration, collect them in advance and upload them as a data source. PTS reads a token from the file for each virtual user.
Platform tokens have a validity period. If tokens expire during the test, requests fail with authentication errors. Verify that your tokens remain valid for at least the planned test duration before you start.
Step 1: Prepare a token file
Create a CSV file named token.csv with a token column header and one token per row. You can create an Excel file and save it as a CSV file, or use Apache Commons CSV to generate a CSV file.
token
T7MeDnBIMKRJdgUB8RNQixyhUPJPaJEG
cqKscgeNWFPkkkaR4dBfcD4A2pD1CYFK
eh3lbjmsjd9jh65xSwvBWvDtmky25CK9Get tokens from your online environment, or generate them in your on-premises environment if your application supports it.
Step 2: Create a PTS scenario
Log on to the PTS console.
Choose Performance Test > Create Scenario, and then click PTS.
Enter a scenario name, such as
myAPP.On the Scenario Settings tab, enter the URL and parameters of your mini program's activity page API.
Step 3: Upload the token file
In the lower part of the scenario page, click Data Sources.
On the Files tab, click + Upload File and upload
token.csv.Select Use First Line as Parameter Name so that PTS uses
tokenas the parameter name and skips the header row when reading data.
Step 4: Bind the token parameter to the API operation
Next to the API operation name, click the
icon and select Add Parameter.Expand the Parameter section. On the Data Source Parameters tab, specify the Parameter Name and click the Copy icon to copy the parameter reference.
Click the Body Definition tab of the API operation. Enter a key name (for example,
token) in the Key field and paste the copied parameter reference in the Value field.
Step 5: Configure load parameters and run the test
In the Stress Mode Configuration section, configure Max VUs and Total Test Duration based on your testing goals.
Click Save and Start.
In the Note dialog box, set Execution Cycle to Execute Now, select the The test is permitted and complies with the applicable laws and regulations checkbox, and then click Start.
PTS capabilities for mini program testing
| Capability | Description |
|---|---|
| TPS mode | Simulate traffic funnel models with Transaction Per Second (TPS) mode for accurate load shaping |
| Geographic distribution | Initiate traffic from all regions across China to simulate real user distribution |
| Diagnostics | View method stack error messages in the built-in diagnostic tool to pinpoint performance bottlenecks |
| Proxy recording | Use client-side proxy recording to reduce the effort of building stress testing scripts |