[JMeter] Parameterize test in command level

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.

  1. Define parameter pass from outside.
    In JMeter test plan, create New 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.

  2. Consume variable in JMeter
    In JMeter test plan, create new HTTP Request Default and set values below:

    Name Value
    Protocol [http] ${protocol}
    Server Name or IP ${host}
    Port Number ${port}

  3. 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 and test-report.csv for API response and its result.

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.