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

查看:199
本文介绍了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不支持包含文件名中的变量,因此我无法通过环境名称对场景进行参数化。 Include Controller支持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:

  • __property()
  • __P()

例如,你可以在 hostname 的属性> jmeter.properties 文件或作为JMeter的命令行参数如下:

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

并在脚本内部引用:


  • $ {__ P(主机名,)}

  • $ {__ property(hostname ,,)}

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

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

See Apache JMeter Properties Customization Guide for more details.

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

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