You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用JMeter对需唯一手机号、邮箱及验证的注册API做100用户压测

Got it, let’s break down exactly how to set up this JMeter load test for your registration API—since you need 100 unique users with distinct phone numbers/emails and have to handle real SMS/email verifications, here’s a practical, step-by-step guide:

1. Generate Unique Phone Numbers & Emails

First, you need to guarantee no two users share the same contact details. Here are reliable methods:

  • Phone Numbers:
    • If you want valid-looking numbers, pre-generate a list of unique ones (e.g., starting with your country’s valid area code, like +1-555-XXX-XXXX) in a CSV file. Use JMeter’s __CSVRead function to pull a unique number per thread/user.
    • For dynamic generation, combine a fixed prefix with __threadNum (to avoid duplicates) and __Random for the rest. Example: ${__Random(10000000,99999999,)} appended to +1555 gives +155512345678—since each thread has a unique ID, this ensures 100 unique numbers.
  • Emails:
    • The easiest way is to use __threadNum in the email address: test-user-${__threadNum()}@example.com. For more realistic addresses, add a random string: ${__RandomString(8,abcdefghijklmnopqrstuvwxyz,)}_user${__threadNum()}@test-domain.com—the thread number guarantees uniqueness even if the random string repeats.
2. Handle SMS Verification Codes

Since your API requires real valid numbers to receive SMS, you have two workable options:

  • Virtual SMS Service Integration: Sign up for a virtual SMS provider that offers an API to fetch verification codes. Add an HTTP Request sampler in JMeter to call this API with your generated phone number, then use a Regular Expression Extractor or JSON Extractor to pull the code into a variable for your registration flow.
  • Pre-Collected Codes: If you can get a list of valid phone numbers paired with pre-generated verification codes, store them in a CSV file (one number + code per row). Use __CSVRead to fetch both values for each user—just make sure rows are unique and codes are valid for the test window.

For email verification, similar logic applies:

  • Email Parsing via IMAP/POP3: Use JMeter’s IMAP Sampler to connect to a dedicated test email inbox. Configure it to search for the verification email sent to your unique address, then extract the link with a Regular Expression Extractor. Add an HTTP Request sampler to hit that link and complete verification.
  • Admin API Shortcut: If your backend has an admin API that can generate verification links without sending emails, call this right after registration to get the link directly. This speeds up testing, but only works if your team allows it.
4. Build Your Load Test Plan Structure

Here’s a clean, logical layout for your JMeter plan:

  1. Thread Group: Set number of threads to 100. Adjust ramp-up time (e.g., 10 seconds = 10 users start per second) based on how you want to simulate user arrival.
  2. CSV Data Set Config (if using pre-generated data): Point to your CSV file, set "Recycle on EOF" to False and "Stop thread on EOF" to True—this ensures each user gets unique data.
  3. User Defined Variables: Store fixed values like API base URL, SMS/email service credentials, etc., for easy updates.
  4. Registration HTTP Request: Plug in your unique phone number and email variables in the request body. Add a Constant Timer (e.g., 5 seconds) if you need to wait for the SMS/email to be sent.
  5. Fetch Verification Code/Link: Add the appropriate sampler (HTTP for SMS API, IMAP for email) to get the code/link, then extract it into a variable.
  6. Submit Verification: Add HTTP requests to submit the SMS code and hit the email verification link.
  7. Listeners: Add Summary Report for aggregate results, View Results Tree for debugging individual requests, and Response Time Graph to analyze performance trends.
5. Critical Tips to Avoid Headaches
  • Validate Uniqueness: Before running the test, double-check your phone numbers/emails are unique. For CSV files, use Excel’s "Remove Duplicates" tool; for dynamic generation, test with a small number of threads first to ensure no overlaps.
  • Respect Rate Limits: SMS/email services often have rate limits—don’t flood them too quickly. Adjust ramp-up time or add Uniform Random Timers to spread out requests.
  • Debug as You Go: Use the __log function to print variables (like generated emails or extracted codes) to the JMeter log, and use the View Results Tree to check each request’s response for errors.
  • Clean Up Test Accounts: If your backend has a delete API, add a final HTTP Request sampler to remove test accounts after the test—this keeps your database clean for future runs.

内容的提问来源于stack exchange,提问作者S Abdullah B Z

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:18:33