本文介绍了JMeter-根据平均响应时间未通过测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用性能插件在Jenkins中运行JMeter作业.如果平均响应时间< 3秒我在jmeter中看到了持续时间断言",但这在每个线程上都有效(每个HTTP请求).而是可以对每个页面平均进行持续时间断言吗?

I am running a JMeter job in Jenkins using performance plugin. I need to fail a job if the average response time < 3 seconds. I see the "duration assertion" in jmeter, but that works on each thread (each http request). Instead is it possible to do the duration assertion on average for each page?

这是我尝试添加BeanSehll侦听器和断言的方法.

This is the way I tried adding the BeanSehll Listener and Assertion.

Recording Controller
       **Home Page**
         BeanShell Listener
         Debug Sampler
       **Page1**
         BeanShell Listener
         Debug Sampler
Beanshell Assertion
View Results Tree

推荐答案

您可以通过 Beanshell 脚本

  1. 在所有活动均处于同一级别的 Beanshell监听器中添加
  2. 将以下代码放入Beanshell Listener的脚本"区域

  1. Add a Beanshell Listener at the same level as all your requests live
  2. Put the following code into Beanshell Listener's "Script" area

String requests = vars.get("requests");
String times = vars.get("times");
long requestsSum = 0;
long timesSum = 0;

if (requests != null && times != null) {
    log.info("requests: " + requests);
    requestsSum = Long.parseLong(vars.get("requests"));
    timesSum = Long.parseLong(vars.get("times"));
}

long thisRequest = sampleResult.getTime();
timesSum += thisRequest;
requestsSum++;

vars.put("requests", String.valueOf(requestsSum));
vars.put("times", String.valueOf(timesSum));


long average = timesSum / requestsSum;

if (average > 3000){
    sampleResult.setSuccessful(false);
    sampleResult.setResponseMessage("Average response time is greater than threshold");
}

上面的代码将记录每个请求的响应时间之和以及进入timesrequests的请求总数. JMeter变量

The code above will record sums of response times for each request and total number of requests into times and requests JMeter Variables

请参见如何使用BeanShell:JMeter最喜欢的内置组件指南,以获取有关Apache JMeter中Beanshell脚本的全面信息.

See How to use BeanShell: JMeter's favorite built-in component guide for comprehensive information on Beanshell scripting in Apache JMeter.

这篇关于JMeter-根据平均响应时间未通过测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:56