All Products
Search
Document Center

Performance Testing:Stress test WeChat mini programs

Last Updated:Mar 11, 2026

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:

ConsiderationMethod 1: Automatic retrieval (recommended)Method 2: Pre-recorded CSV file
Test durationAny durationMust be shorter than the token validity period
Setup effortRequires a custom token-retrieval endpointRequires collecting tokens manually
Token freshnessAlways current -- PTS refreshes tokens automaticallyTokens may expire mid-test
Best forProduction-grade stress tests, long-running testsQuick 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:

  1. Build a token-retrieval API endpoint

  2. Create a PTS scenario with two sequential API operations

  3. Configure the first operation to output the access token

  4. Configure the second operation to consume the token

  5. 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

  1. Log on to the PTS console.

  2. Choose Performance Test > Create Scenario, and then click PTS.

  3. 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.

  1. On the Scenario Settings tab, expand the first API operation and enter the URL and parameters of your token-retrieval endpoint.

  2. Click the Output Parameter Definition tab and configure the following settings: PTS uses the parsing expression to locate the access_token field in the JSON response body shown in Step 1.

    FieldValue
    Output Parameter Nameaccess_token
    SourceBody:JSON
    Parsing Expressionaccess_token

    Output parameter definition

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.

  1. Click Add API to add a second API operation.

  2. Enter the URL of your mini program's activity page API. Set the request method to POST.

  3. Pass the access token to this API operation:

    1. In the lower part of the page, click Parameters. In the Parameters panel, click Session Parameters.

    2. Click the Copy icon next to the access_token output parameter to copy the parameter reference.

      Copy session parameter

    3. 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.

      Body definition configuration

Step 5: Configure load parameters and run the test

  1. In the Stress Mode Configuration section, configure load parameters based on your testing goals:

    Note

    For guidance on choosing a stress testing model, see Configure the stress testing model and level.

    ParameterDescription
    Max VUsMaximum number of virtual users to simulate
    Total Test DurationHow long the test runs
  2. Click Save and Start.

  3. 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.

Note

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.

Important

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
eh3lbjmsjd9jh65xSwvBWvDtmky25CK9
Note

Get tokens from your online environment, or generate them in your on-premises environment if your application supports it.

Step 2: Create a PTS scenario

  1. Log on to the PTS console.

  2. Choose Performance Test > Create Scenario, and then click PTS.

  3. Enter a scenario name, such as myAPP.

  4. On the Scenario Settings tab, enter the URL and parameters of your mini program's activity page API.

Step 3: Upload the token file

  1. In the lower part of the scenario page, click Data Sources.

  2. On the Files tab, click + Upload File and upload token.csv.

  3. Select Use First Line as Parameter Name so that PTS uses token as the parameter name and skips the header row when reading data.

Step 4: Bind the token parameter to the API operation

  1. Next to the API operation name, click the More icon and select Add Parameter.

  2. Expand the Parameter section. On the Data Source Parameters tab, specify the Parameter Name and click the Copy icon to copy the parameter reference.

  3. 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.

    Body definition with token

Step 5: Configure load parameters and run the test

  1. In the Stress Mode Configuration section, configure Max VUs and Total Test Duration based on your testing goals.

  2. Click Save and Start.

  3. 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

CapabilityDescription
TPS modeSimulate traffic funnel models with Transaction Per Second (TPS) mode for accurate load shaping
Geographic distributionInitiate traffic from all regions across China to simulate real user distribution
DiagnosticsView method stack error messages in the built-in diagnostic tool to pinpoint performance bottlenecks
Proxy recordingUse client-side proxy recording to reduce the effort of building stress testing scripts