【问题标题】:How to get an overall PASS/FAIL result for a JMeter thread group如何获得 JMeter 线程组的总体通过/失败结果
【发布时间】:2018-04-27 09:12:38
【问题描述】:

如何在每个采样器上不使用后处理器的情况下获得 JMeter 线程组的总体通过/失败结果?

我尝试使用 beanshell 侦听器,但它不适用于启用“生成父样本”的事务控制器内有多个采样器的情况。在这种情况下,每个事务控制器只会调用一次侦听器,而我只能访问事务控制器内最后一个采样器的结果。

编辑:

我希望能够将通过/失败值保存为线程组的 Jmeter 变量或属性。如果线程组的一个或多个组件失败或返回错误,那么这将是一个整体失败。然后,此变量将用于报告目的。

我当前的 beanshell 监听代码:

SampleResult sr = ctx.getPreviousResult();

log.info(Boolean.toString(sr.isSuccessful()));

if (!sr.isSuccessful()){
    props.put("testPlanResult", "FAIL");

    testPlanResultComment = props.get("testPlanResultComment");

    if(testPlanResultComment == ""){
            testPlanResultComment = sr.getSampleLabel();
    }else {
            testPlanResultComment = testPlanResultComment + ", " + sr.getSampleLabel();
    }

    props.put("testPlanResultComment", testPlanResultComment);
    log.info(testPlanResultComment);
}

【问题讨论】:

  • 请提供更多信息/图表/图片/代码,说明您正在尝试什么以及您希望它是什么样的。总体通过/失败不是很清楚。

标签: jmeter performance-testing


【解决方案1】:

如果您调用prev.getParent(),您将能够通过getSubResults() 函数获取各个子样本,例如:

prev.getParent().getSubResults().each {result ->
    log.info('Sampler: ' + result.getSampleLabel() + ' Elapsed time: ' + result.getTime() )
}
log.info('Total: ' + prev.getParent().getTime())

演示:

更多信息:Apache Groovy - Why and How You Should Use It

【讨论】:

    猜你喜欢
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 1970-01-01
    相关资源
    最近更新 更多