JMeter 环境特定配置 [英] JMeter environment specific configuration

查看:24
本文介绍了JMeter 环境特定配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 JMeter 测试计划,它们应该在不同的环境中执行,比如 Dev、Test、UAT、Live.在每个测试计划中,我都希望有一种简单的方法来指定要使用的环境.每个环境都有很多配置,比如主机名、端口、ssl-cert、用户名、密码、账号等测试数据.

I have several JMeter test plans which should be executed in different environments, say Dev, Test, UAT, Live. In each test plan I would like to have a simple way to specify which environment to use. Each environment has a lot of configuration such as hostname, port, ssl-cert, user name, password, account numbers and other test data.

我想要实现的一件事是在使用 JMeter GUI 或从构建脚本运行场景时轻松切换环境.

One thing I'm trying to achieve is the ease of switching environments while using JMeter GUI or running scenarios from build scripts.

我的一个想法是使用包含控制器"来包含另一个 jmx 文件,其中包含用户定义的变量和其他配置元素的列表.但是,JMeter 不支持包含的文件名中的变量,因此我无法通过环境名称对场景进行参数化.包含控制器支持 JMeter 参数includecontroller.prefix",但它不是很灵活,例如我无法从 JMeter GUI 更改它,我应该更改 JMeter 配置文件并重新启动它.

One of my ideas is to use the "Include Controller" to include another jmx file which has list of User Defined Variables and other config elements. However, JMeter does not support variables in the included file name, so I cannot parametrise the scenario by an environment name. Include Controller supports JMeter parameter "includecontroller.prefix", but it is not very flexible, e.g. I cannot change it from JMeter GUI, I should change JMeter config files and restart it.

我曾尝试使用 Switch Controller,但没有成功,它不会切换配置元素,只会切换采样器.

I've tried to use Switch Controller, but no luck, it doesn't switch configuration elements, only samplers.

从测试场景中具体化环境特定配置并在多个场景之间共享它的最佳实践是什么?

What is the best practice to externalise environment specific configuration from test scenarios and share it between several scenarios?

推荐答案

我建议用 JMeter 属性替换所有特定于环境的变量或值.参考以下函数:

I would suggest to substitute all environment-specific variables or values with JMeter Properties. See following functions for reference:

例如,您可以在 jmeter.properties 文件或 JMeter 命令行参数中定义一个名为 hostname 的属性,如下所示

For example you can define a property called hostname in either jmeter.properties file or as JMeter command line argument as follows

jmeter -Jhostname=169.140.130.120 -n -t yourscript.jmx -l yourscriptresults.jtl

并在您的脚本中引用为:

and refer to in inside your script as:

  • ${__P(hostname,)}
  • ${__property(hostname,,)}

有关详细信息,请参阅 Apache JMeter 属性自定义指南.

See Apache JMeter Properties Customization Guide for more details.

这篇关于JMeter 环境特定配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆