Properties and Variables

Properties and Variables

Properties and Variables- JMeter properties are defined in JMeter.properties (see Getting Started – Configuring JMeter for more details). Properties are global to JMeter and are mostly used to define some of the defaults JMeter uses. For example, the property remote_hosts defines the servers that JMeter will try to run remotely. Properties can be referenced in test plans – see functions – read a property – but cannot be used for thread-specific values.

JMeter variables are local to each thread. The values may be the same for each thread, or they may be different.

If a variable is updated by a thread, only the thread copy of the variable is changed. For example the Regular Expression Extractor Post-Processor will set its variables according to the sample that its thread has read, and these can be used later by the same thread. For details of how to reference variables and functions, see Functions and Variables

Note that the values defined by the Test Plan and the User Defined Variablesconfiguration element are made available to the whole test plan at startup. If the same variable is defined by multiple UDV elements, then the last one takes effect. Once a thread has started, the initial set of variables is copied to each thread. Other elements such as the User Parameters Pre-Processor or Regular Expression Extractor Post-Processor may be used to redefine the same variables (or create new ones). These redefinitions only apply to the current thread.

The setProperty function can be used to define a JMeter property. These are global to the test plan, so can be used to pass information between threads – should that be needed. Both variables and properties are case-sensitive. 

Using Variables to parameterize tests

Variables don’t have to vary – they can be defined once, and if left alone, will not change value. So you can use them as short-hand for expressions that appear frequently in a test plan. Or for items that are constant during a run, but which may vary between runs. For example, the name of a host, or the number of threads in a thread group.

When deciding how to structure a Test Plan, make a note of which items are constant for the run, but which may change between runs. Decide on some variable names for these – perhaps use a naming convention such as prefixing them with C_ or K_ or using uppercase only to distinguish them from variables that need to change during the test. Also consider which items need to be local to a thread – for example, counters or values extracted with the Regular Expression Post-Processor. You may wish to use a different naming convention for these.

For example, you might define the following on the Test Plan:

HOST             www.example.com

THREADS          10

LOOPS            20

You can refer to these in the test plan as ${HOST} ${THREADS} etc. If you later want to change the host, just change the value of the HOST variable. This works fine for small numbers of tests, but becomes tedious when testing lots of different combinations. One solution is to use a property to define the value of the variables, for example:

HOST             ${__P(host,www.example.com)}

THREADS          ${__P(threads,10)}

LOOPS            ${__P(loops,20)}

You can then change some or all of the values on the command-line as follows:

jmeter … -Jhost=www3.example.org -Jloops=13

Test Your Software Testing Skills By Taking Our JMeter Practice Tests On This Link

Become Vskills Certified JMeter Tester. Gain some knowledge on the module “Properties and Variables”. Try the free practice test!

Apply For JMeter Certification

Go back to Tutorial

Share this post
[social_warfare]
Assertions & Execution Order
BUILDING A WEB TEST PLAN

Get industry recognized certification – Contact us

keyboard_arrow_up