skip to content

In JMeter, what does ${__P(base.url)} return when base.url is not set?

level: middleimportance: should knowfreq 45%

answer

  1. It does not fail and does not stay empty
  2. The fallback suits a count, not a URL
  3. The two functions disagree on their default
  4. One returns a digit, the other the key name

basics

~10 s

The literal string 1. JMeter's __P function uses 1 as its built-in default when no second argument is given, so an unset property silently resolves to 1 rather than raising an error.

solid answer

~40 s

`__P` takes a property name and an optional default. When the second argument is omitted, `Property2.execute` sets the default to the literal `"1"` before looking the property up, so an unset key silently resolves to `1`. That default suits the numeric plan fields the function is most often used in, but it is applied to **any** unset property. `${__P(base.url)}` yields the string `1`, which goes into the field as-is and produces a request to a host called `1`. The older `__property` function differs: with no third argument, `Property.execute` uses the **property name itself** as the default, so `${__property(base.url)}` returns the literal `base.url`. Neither function fails on a missing property. Always pass an explicit default — `${__P(base.url,http://localhost:8080)}` — so a typo produces something you can recognise.

code

text · 6 lines
text
# base.url is not set anywhere. JMeter 6.0.0 resolves:

${__P(base.url)}                    ->  1
${__P(base.url,http://localhost)}   ->  http://localhost
${__property(base.url)}             ->  base.url
${__property(base.url,,localhost)}  ->  localhost

go deeper

for a junior

Remember that ${__P(name)} takes an optional default as its second argument, and get into the habit of always supplying one. An unset property does not stop the run.

for a middle

State the actual fallback values: __P uses the literal 1 and __property uses the property name. Explain why an unset property surfaces as a strange request rather than as an error.

for a senior

Connect the default to the symptom you would see in a real run. A request to the host 1 with no mention of a property anywhere in the output is the signature of an unset key and a missing default.

for a principal

Decide what the team does about required values. There is no fail-fast property mode, so either every reference carries a recognisable default or the plan checks its own inputs before load starts.

Neither of JMeter's property-reading functions fails when the property is missing. Both substitute a default, both defaults are surprising, and both are surprising in different ways. That is why an unset property produces a strange value in a request rather than an error in the log. ## What __P does with no second argument `__P` takes a property name and an optional default. In `Property2.execute`, the default is initialised before the arguments are inspected: String propertyDefault = "1"; if (values.length > 1) { propertyDefault = ((CompoundVariable) values[1]).execute(); } String propertyValue = JMeterUtils.getPropDefault(propertyName, propertyDefault); So `${__P(base.url)}` against an unset `base.url` resolves to the literal string `1`. The choice makes sense for the numeric plan fields this function is most often used in, where a count of one is a harmless fallback. It is applied unconditionally, though, so a URL, a hostname, a file path or a credential all fall back to `1` just the same. The failure that follows is confusing out of context: a request goes to the host `1`, DNS resolution fails, and nothing in the output mentions a property at all. ## What __property does with no third argument `__property` is the older function and takes a name, an optional variable name to store the result in, and an optional default. In `Property.execute` the default is the **property name itself**: String propertyDefault = propertyName; if (values.length > 2) { propertyDefault = ((CompoundVariable) values[2]).execute(); } `${__property(base.url)}` against an unset key therefore returns the literal string `base.url`. This one is at least self-describing — seeing `base.url` where a URL should be tells you immediately which key was not set. ## The two side by side | Expression | Property set | Property unset | |---|---|---| | `${__P(base.url)}` | the value | `1` | | `${__P(base.url,http://localhost:8080)}` | the value | `http://localhost:8080` | | `${__property(base.url)}` | the value | `base.url` | | `${__property(base.url,,http://localhost:8080)}` | the value | `http://localhost:8080` | The empty second argument in the last row is the variable-name slot, which `__property` accepts as empty and skips. ## Practical consequences - **Always pass an explicit default to `__P`.** `${__P(base.url,http://localhost:8080)}` turns an unset property into something recognisable, and a run against localhost that fails to connect is a far clearer signal than a run against the host `1`. - **A missing property never stops the run.** There is no strict mode and no fail-fast flag for property resolution in JMeter 6.0.0, so if a run must not proceed without a value, the plan has to assert that itself. - **Choose a default that cannot be mistaken for real data.** A default equal to a plausible production value hides the mistake instead of exposing it. - **The second argument of `__property` is a variable name, not a default.** Passing a default there stores the resolved value into a variable of that name, which is a different feature and a common misreading of the signature. ## Which to reach for `__P` is the shorter, more commonly used form, and it is the one to use in new plans. Reach for `__property` when you specifically want its middle argument: resolving a property once and capturing it into a per-thread variable in the same expression, so that later references read the cheaper variable.

  • Why would JMeter pick 1 as the built-in default rather than an empty string?
    Because __P is most often used for numeric plan fields, where a fallback of one is valid and harmless. The value is applied to every unset property regardless of what the field expects, which is why it looks wrong in a URL.
  • Can JMeter be made to abort when a required property is missing?
    Not by property resolution itself; there is no strict or fail-fast mode for ${__P(...)} in JMeter 6.0.0. If a run must not proceed without a value, the plan has to check it explicitly and stop the run itself.
  • What does the second argument of ${__property(name,var)} do?
    It names a variable to store the resolved value in, not a default. The default is the third argument. Supplying only two arguments therefore captures the value into a variable while still falling back to the property name when the key is unset.

saying these in an interview costs you the question

  • Says an unset property makes ${__P(...)} return an empty string
  • Expects JMeter to fail or warn when a property is missing
  • Treats the second argument of __property as its default
  • Assumes __P and __property fall back to the same value
  • Omits the default and blames DNS when the host becomes 1