Overview of Apache JMeter
Apache JMeter is an open-source Java-based desktop application developed by the Apache Software Foundation. Originally designed for web application testing, it has evolved into a versatile tool for load and performance testing across various domains.
Core Capabilities
JMeter provides comprehensive testing features including:
- Load and performance testing for HTTP and FTP servers
- Database testing through JDBC connectivity
- Platform independence with pure Java implementation
- Multi-threaded framework supporting concurrent sampling
- Intuitive graphical interface for efficient test creation
- Result caching and offline analysis capabilities
Installation and Environment Setup
JMeter is available in two distributions:
- Source distribution: Requires compilation from source code
- Binary distribution: Pre-compiled executable version
Extract the downloaded package to a directory with out spaces in the path. JMeter requires Java Development Kit (JDK) to be installed and properly configured in the system environment variables.
Launch the application by executing JMeter.bat from the bin directory.
Creating HTTP Requests
Basic request creation involves these steps:
- Add Thread Group
- Configure HTTP Request sampler
- Specify URL, path, method, and parameters
- Add View Results Tree listener
- Execute and monitor response
GET Request Example
http://httpbin.org/get
Configure the HTTP Request sampler with the target URL and method type.
POST Request Example
http://httpbin.org/post
Set method to POST and configure request body as needed.
HTTP Request Defaults Configuration
To avoid repetitive configuration of common parameters like protocol and server name, use HTTP Request Defaults:
Add through Thread Group → Add → Config Element → HTTP Request Defaults
This element should be placed before request samplers to apply default values.
Response Validation
JMeter supports response assertions for verification:
Add through right-click request → Add → Assertions → Response Assertion
Assertion types include:
- Contains: Response includes specified content (regex supported)
- Matches: Full response matches pattern (case-insensitive, regex supported)
- Equals: Exact string match (case-sensitive)
- Substring: Contains specified substring (no regex support)
Parameter Configuration
Query Parameters
Add parameters in the HTTP Request sampler's Parameters tab. These are appended to the URL as query strings.
Request Body Parameters
For POST requsets, parameters can be sent in the request body. For JSON data:
{ "username" : "huang" }
Include HTTP Header Manager to set Content-Type: application/json.
Variable Management
User Defined Variables
Create through Thread Group → Add → Pre Processors → User Parameters
Reference variables using ${variable_name} syntax.
Function Helper
Generate dynamic values using built-in functions like __Random() through Options → Function Helper Dialog.
BeanShell Variables
BeanShell provides scripting capabilities with Java-like syntax. Key components include:
- BeanShell PreProcessor
- BeanShell PostProcessor
- BeanShell Sampler
Common built-in variables:
// Set JMeter variable
vars.put("key", "value");
// Get JMeter variable
vars.get("key");
// Log messages
log.info("message");
CSV Data Integration
Import external data through CSV Data Set Config:
Thread Group → Add → Config Element → CSV Data Set Config
Sample CSV content:
huang,8888
Configuration options:
- Filename: Path to CSV file
- Variable Names: Column variable names (comma-separated)
- Delimiter: Field separator (comma, tab, etc.)
- Recycle on EOF: Restart from beginning when end reached
- Stop thread on EOF: Terminate thread when end reached
Regular Expression Extraction
Extract data from responses for use in subsequent requests:
Add through Thread Group → Add → Post Processors → Regular Expression Extractor
Configuration parameters:
- Reference Name: Variable name for extracted data
- Regular Expression: Pattern to match
- Template:
$1$for first capture group - Match No.:
0for random,1for first match - Default Value: Fallback when no match found
Example pattern to extract host:
"host":\s*"([^"]+)"
Reference extracted values in subsequent requests using ${reference_name} syntax.