JMeter 如何避免失败 500 内部服务器错误 [英] JMeter how to NOT fail 500 Internal Server Errors

查看:32
本文介绍了JMeter 如何避免失败 500 内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在参数化调用中使用 JMeter 作为单元测试工具,我预计其中一些响应是 500 个内部服务器错误.我正在使用 BeanShell 断言来检查响应.

I am using JMeter as a unit test tool, in parameterised calls where I expect some of the responses to be 500 internal server errors. I am using BeanShell Assertions to check the responses.

如果响应包含指定的文本,我希望 500 个内部服务器错误中的一些不被标记为失败.所有 500 个服务器错误都标记为失败.是否可以改变行为?

I want some of the 500 internal server errors to NOT be marked as failures if the response contains a specified text. All 500 server errors are marked as failures. Is it possible to change the behavior?

以下是 BeanShell 断言的摘录.

Below is an extract from the BeanShell Assertion.

if (ResponseCode.equals("500")) {
    Failure = false;
    String respData = new String(ResponseData);

    if (! respData.contains("specific Text")) {
        Failure = true;
        FailureMessage = "500 Internal Server Error:  Unexpected Response.   " + 
            "Response Message: " + respData;
    }
}  

谢谢和问候

推荐答案

UPD:请找到最简单的 &下面的原生"解决方案:

UPD: please find most simple & "native" solution below:

如果您想在代码中做一些棘手的事情,请使用以下方法.

In case if you want to do some tricky things in code use the following approach.

访问和修改SampleResult 来改变状态如果您的 JSR223 断言中的代码为 500,则从失败"到通过"或者改用 JSR223 PostProcessor - 他们都可以访问 SampleResult 对象.

Access and modify SampleResult to change the status from "FAIL" to "PASS" if the code is 500 from your JSR223 Assertion or use JSR223 PostProcessor instead - they all have access to SampleResult Object.

1.JSR223 断言

if (ResponseCode.equals("500") == true) { 
    SampleResult.setResponseOK();  

    /* the same is 
    SampleResult.setSuccessful(true);
    SampleResult.setResponseCodeOK();
    SampleResult.setResponseMessageOK();
    */
}

2.JSR223 后处理器
改用 prev - 访问附加了一个后处理器的采样器的 SampleResult 对象:

2. JSR223 PostProcessor
Use prev instead - to access SampleResult object of the sampler to which one post-processor is attached:

if (prev.getResponseCode().equals("500") == true) { 
    prev.setResponseOK();  

    /* the same is 
    prev.setSuccessful(true);
    prev.setResponseCodeOK();
    prev.setResponseMessageOK();
    */
}

这篇关于JMeter 如何避免失败 500 内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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