JMeter 함수와 변수
스크립트를 유연하게 작성할 수 있도록 JMeter의 기본 제공 함수와 사용자 정의 변수를 살펴봅니다.
JMeter 함수와 변수은(는) CoddyKit의 무료 Load Testing & Performance Benchmarking (JMeter & k6) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Load Testing & Performance Benchmarking (JMeter & k6) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Dynamic Data in JMeter
Welcome! In performance testing, it's rare for all users to do the exact same thing or use the exact same data.
To simulate real-world scenarios, your test scripts need to be flexible and dynamic. This lesson explores how to achieve this using JMeter's built-in functions and user-defined variables.
What are JMeter Variables?
A JMeter Variable is a placeholder that stores a value. Think of it like a temporary name tag for a piece of information.
- They make your test scripts more readable.
- They allow you to reuse values throughout your test plan.
- Changing a value once updates it everywhere it's used.
This is crucial for maintainability and flexibility.
User Defined Variables (UDVs)
The simplest way to create variables in JMeter is using the User Defined Variables element.
You can add this element under your Test Plan or a Thread Group. Here, you define a variable name and its corresponding value.
This is perfect for static values you want to manage centrally, like a base URL or a default username.
Add Element:
Test Plan > Add > Config Element > User Defined Variables
Configuration:
Name: BASE_URL
Value: http://example.com
Name: USER_COUNT
Value: 100Using UDVs in Requests
Once defined, you can reference your User Defined Variables anywhere in your test plan using the syntax ${variableName}.
JMeter will replace this placeholder with the actual value of the variable during test execution.
HTTP Request Sampler:
Protocol: http
Server Name or IP: ${BASE_URL}
Path: /login
HTTP Header Manager:
Name: X-User-Count
Value: ${USER_COUNT}Introducing JMeter Functions
While variables store fixed or manually updated values, JMeter Functions generate dynamic values during runtime.
Functions start with ${__functionName(...)} and can take parameters. They help simulate more realistic user behavior, like generating random numbers or unique IDs.
The __Random Function
The __Random function generates a random integer within a specified range.
Its syntax is ${__Random(min, max, variableName)}:
min: The smallest number to generate.max: The largest number to generate.variableName: (Optional) A variable to store the generated value.
This is great for picking random items from a list or simulating varying input.
Example:
${__Random(1, 10,)}
// Generates a random number between 1 and 10
${__Random(100, 999, myRandomID)}
// Generates a random number between 100 and 999
// and stores it in a variable named 'myRandomID'Using __Random in a Test
Let's say you want to simulate users accessing random product IDs on an e-commerce site. You can use __Random directly in your HTTP Request path.
This helps distribute the load across different resources, mimicking real user behavior.
HTTP Request Sampler:
Protocol: http
Server Name or IP: ${BASE_URL}
Path: /products/${__Random(1001, 2000,)}
// This would access paths like:
// /products/1543
// /products/1987
// etc.The __counter Function
The __counter function generates a sequence of unique numbers. It's useful when you need to provide unique identifiers or sequential data.
Its syntax is ${__counter(true/false, variableName)}:
true: Counter is global across all thread groups.false: Counter is local to each thread.variableName: (Optional) A variable to store the generated value.
Example:
${__counter(false,)}
// Generates 1, 2, 3... for each thread independently
${__counter(true, globalCount)}
// Generates 1, 2, 3... globally across all threads
// and stores it in 'globalCount'Using __counter for Unique IDs
Imagine you're testing an order creation API where each order needs a unique ID. Using __counter ensures that every request sends a distinct order ID.
This is vital for avoiding data conflicts and accurately simulating transactions.
HTTP Request Sampler:
Method: POST
Path: /orders
Body Data:
{
"orderId": "ORDER-${__counter(true,)}",
"customerName": "Test User"
}
// Example Body Data:
// {"orderId": "ORDER-1", ...}
// {"orderId": "ORDER-2", ...}Functions & Variables Quiz
Which of the following statements about JMeter variables and functions are TRUE?
Recap: Functions & Variables
Great job! You've learned how to make your JMeter tests more dynamic and realistic:
- JMeter Variables provide placeholders for reusable values like base URLs.
- User Defined Variables (UDVs) are a simple way to define these static variables.
- JMeter Functions generate values dynamically during test runtime.
- The
__Randomfunction creates random numbers for varied inputs. - The
__counterfunction generates unique, sequential numbers.
Mastering these will significantly improve the flexibility and accuracy of your load tests!
자주 묻는 질문
“JMeter 함수와 변수” 강의는 무료인가요?
네 — “JMeter 함수와 변수” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Load Testing & Performance Benchmarking (JMeter & k6) 강의 전체를 잠금 해제할 수 있습니다. Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 총 4개의 강의가 포함되어 있습니다.
“JMeter 함수와 변수”에서 뭘 배우나요?
스크립트를 유연하게 작성할 수 있도록 JMeter의 기본 제공 함수와 사용자 정의 변수를 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 Load Testing & Performance Benchmarking (JMeter & k6)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Load Testing & Performance Benchmarking (JMeter & k6)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Load Testing & Performance Benchmarking (JMeter & k6)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“JMeter 함수와 변수” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Load Testing & Performance Benchmarking (JMeter & k6) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Load Testing & Performance Benchmarking (JMeter & k6) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- CSV 데이터로 매개변수화
- 동적 값 처리(상관관계)
- JMeter 함수와 변수
- JDBC를 사용한 데이터베이스 시험