JMeter is a free testing tools on SIT and load test in web API. It can execute test with command and GUI. To enable CI / CD, it is required to expose parameter which pass from outsider.This demo will try to pass parameter protocol
, host
and port
from outside to enable jmx file can test in different environment. Steps as below.
- Define parameter pass from outside.
In JMeter test plan, createNew User Defined Variable
, and input name and value in format below:Name Value protocol ${__P(protocal,http)} host ${__P(host,localhost)} port ${__P(port,8964)} In JMeter
${__}
reserved for JMeter for specific purpose,${__P([variable name],[default value])}
is JMeter get value from command parameter. If not found, it will use default value if set.
- Consume variable in JMeter
In JMeter test plan, create newHTTP Request Default
and set values below:Name Value Protocol [http] ${protocol} Server Name or IP ${host} Port Number ${port} - Test with command.
In command prompt, execute command below:set JEMTER_HOME=C:\Apps\apache-jmeter-5.4.1 set JMX_PATH=C:\test-app\jmeter $JMETER_HOME\bin\jmeter.bat -n -t $JMX_PATH\Users.jmx -Jprotocal=https -Jhost=dummy.com -Jport=443 -l test-report.csv
After execute, it will generate
jmeter.log
for execution log andtest-report.csv
for API response and its result.
Leave a Reply