Stefan Siegl
12. March 2013
2 min

How to pass command line properties to a JMeter testplan

JMeter differentiates between variables and properties. This difference often leads to confusions. Within your testplan you probably often define variables. Often variables are defined within the testplan.

As you can see HOST and PORT are defined and can be used throughout the testplan using ANT style references like ${HOST} and ${PORT}. Thus you can create tests that are independent of the host and the port, but you have to change the testplan. Often you want to define the host and port simply when you execute your loadtest.

Now comes the pitfall: Variables cannot be set via the command line! Cannot and – as far as I get it – never will. But there is an alternative: properties.

Properties can be defined from the command line, and can be read from the testplan using an – in my opinion – quite ugly syntax: ${__P([property],[defaultvalue])}. Properties are passed using the -J option to the jmeter start. So executing

sets the properties HOST and PORT. But there is a drawback with properties. Properties cannot be set easily within JMeter itself. You have to resort to beanshell expressions to change them.

Suggestions on usage:

Only use variables within your testplan. Even though you now realize that there is a difference between properties and variables, that guy that will maintain your loadtest when you are on holiday will most probably not and he will be confused seeing mixed references like ${HOST} and ${__P([PORT],[80])} within the testplan.

Thus what I always do is to allow variables to be initialized with properties, but only use variables internally. To do that I define my variables on the testplan and allow there variables to be initialized with a property, but always use the variable within the testplan:

jmeter_variables_parameters_testplan

Conclusion

Properties and variables can lead to some confusion when using JMeter. In my opinion it is meaningful to use only variables within the testplan itself to not further confuse maintainers. So what do you think? How do you tackle the property/variable issue in JMeter?

–Stefan

Comment article