有没有办法以编程方式确定JMeter是否在“功能测试模式"下运行? [英] Is there a way to programatically determine whether JMeter is being run in 'functional test mode'?

查看:186
本文介绍了有没有办法以编程方式确定JMeter是否在“功能测试模式"下运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我承担了实现一组JMeter测试的任务,这些测试可用于REST api的性能或功能测试.为此,我希望能够在性能测试过程中跳过错误案例请求和较重的声明,以保持模拟流量的真实性,并使运行测试的计算机的开销较低. 现在,我正在确定是否通过用户定义的变量将测试作为性能测试执行.如果其值为"true",则将跳过某些请求和断言.流是通过Groovy中的JSR223脚本控制的. 该解决方案效果很好,但是当JMeter已经具有功能测试模式"复选框时,让UDV困扰我.我无济于事地寻找一种以编程方式检查该复选框状态的方法.有什么办法可以让我丢失,或者是我坚持使用半冗余的UDV吗?

I've been given the task of implementing a set of JMeter tests that can be used for either performance or functional testing of a REST api. To do this, I want to be able to skip error case requests and heavier weight assertions during a performance test to keep the simulated traffic realistic and the overhead on the machine running the test low. Right now I'm determining whether the tests are executed as a performance test via a User Defined Variable. If it's value is 'true' some requests and assertions are skipped. Flow is controlled via JSR223 scripts in Groovy. The solution works just fine, but having that UDV annoys me when JMeter already has a checkbox for 'Functional Test Mode'. I have searched to no avail for a way to programatically check the state of that checkbox. Is there a way I am missing, or am I stuck with a semi-redundant UDV?

推荐答案

就是这样,假设您已经使用了JSR223和Groovy,则可以从Functional Test Mode设置. org/api/org/apache/jmeter/testelement/TestPlan.html#isFunctionalMode--"rel =" nofollow noreferrer> TestPlan类如下:

It is, given you already use JSR223 and Groovy you can obtain the Functional Test Mode setting from the TestPlan class as follows:

import org.apache.jmeter.engine.StandardJMeterEngine
import org.apache.jmeter.testelement.TestPlan
import org.apache.jorphan.collections.HashTree
import org.apache.jorphan.collections.SearchByClass

import java.lang.reflect.Field

StandardJMeterEngine engine = ctx.getEngine()
Field test = engine.getClass().getDeclaredField("test")
test.setAccessible(true)
HashTree testPlanTree = (HashTree) test.get(engine)

SearchByClass<TestPlan> testPlanSearch = new SearchByClass<>(TestPlan.class)
testPlanTree.traverse(testPlanSearch)
Collection<TestPlan> testPlans = testPlanSearch.getSearchResults()
TestPlan testPlan = testPlans[0]

log.info('Functional test mode: ' + testPlan.isFunctionalMode())

演示:

请参见 JMeter的Groovy模板速查表有关如何在JMeter脚本中使用Groovy的更多示例.

See The Groovy Templates Cheat Sheet for JMeter for more examples on how Groovy can be used in JMeter scripts.

这篇关于有没有办法以编程方式确定JMeter是否在“功能测试模式"下运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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