jmeter beanshell Typed variable declaration : Object constructor错误

从数据库取值和响应值做比较,使用beanshell如下:

import org.json.JSONArray;
import org.json.JSONObject;

res_str = prev.getResponseDataAsString();
JSONObject res_json_obj = new JSONObject(res_str);
JSONArray dbd_json_array = new JSONArray("${dbd}"); // 数据库转json
JSONObject dbd_json_obj = new JSONObject();
FailureMessage = "";
Failure = true;

res_json_obj = new JSONObject(res_json_obj.get("data").toString());
if (!res_json_obj.isNull("list")) {
    JSONArray res_json_array = new JSONArray(res_json_obj.get("list").toString());
    log.info("响应长度:" + res_json_array.length());
    log.info("数据返回长度:" + dbd_json_array.length());

    if (res_json_array.length() == dbd_json_array.length()) {
        for (int i = 0; i < dbd_json_array.length(); i++) {
            Message = "\n第"+i+"条记录:";
            res_json_obj = res_json_array.getJSONObject(i);
            dbd_json_obj = dbd_json_array.getJSONObject(i);

            System.out.println(res_json_obj);

            Iterator keys = dbd_json_obj.keys();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                String resvalue="";
                String dbdvalue="";

                System.out.println("key:" + key);
                if (key.equals(null) || key.equals("")) {
                    Message += key + "不存在;";
                    FailureMessage += Message;
                    Failure = true;
                    log.info(Message);
                    break;
                    }

                        if(res_json_obj.has(key) && dbd_json_obj.has(key)) {
                            resvalue = res_json_obj.getString(key);
                            dbdvalue = dbd_json_obj.getString(key);
                        }else {
                            Message += key + "不存在;";
                            FailureMessage += Message;
                            Failure = true;
                            log.info(Message);
                            break;
                        }

                        if (resvalue.equals(dbdvalue)) {
                            Message += key + "匹配成功;";
                            Failure = false;
                        } else {
                            Message += key + "匹配不成功,数据库值:" + dbdvalue + ",响应值:"+resvalue;
                            FailureMessage += Message;
                            Failure = true;
                            log.info(Message);
                            break;

                        }

                        log.info("value:" + res_json_obj.get(key));
                    }
                }

            } else {
                Message += "接口响应与数据库数据不匹配;";
                 Message += "响应数据:" + res_json_array + "|数据库查询结果:" + dbd_json_array;
                 FailureMessage += Message;
                Failure = true;
                log.info("value:" + res_json_obj.get(key));
                break;
            }

        } else {
            FailureMessage = "返回数据为空";
            log.info(FailureMessage);
            Failure = true;
            return;
        }

import org.json.JSONArray;
import org.json.JSONObject;

res_str = prev.getResponseDataAsString();
JSONObject res_json_obj = new JSONObject(res_str);
JSONArray dbd_json_array = new JSONArray("${dbd}"); // 数据库转json
JSONObject dbd_json_obj = new JSONObject();
FailureMessage = "";
Failure = true;

res_json_obj = new JSONObject(res_json_obj.get("data").toString());
if (!res_json_obj.isNull("list")) {
JSONArray res_json_array = new JSONArray(res_json_obj.get("list").toString());
log.info("响应长度:" + res_json_array.length());
log.info("数据返回长度:" + dbd_json_array.length());

if (res_json_array.length() == dbd_json_array.length()) {
for (int i = 0; i < dbd_json_array.length(); i++) {
Message = "\n第"+i+"条记录:";
res_json_obj = res_json_array.getJSONObject(i);
dbd_json_obj = dbd_json_array.getJSONObject(i);

System.out.println(res_json_obj);

Iterator keys = dbd_json_obj.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
String resvalue="";
String dbdvalue="";

System.out.println("key:" + key);
if (key.equals(null) || key.equals("")) {
Message += key + "不存在;";
FailureMessage += Message;
Failure = true;
log.info(Message);
break;
}

if(res_json_obj.has(key) && dbd_json_obj.has(key)) {
resvalue = res_json_obj.getString(key);
dbdvalue = dbd_json_obj.getString(key);
}else {
Message += key + "不存在;";
FailureMessage += Message;
Failure = true;
log.info(Message);
break;
}

if (resvalue.equals(dbdvalue)) {
Message += key + "匹配成功;";
Failure = false;
} else {
Message += key + "匹配不成功,数据库值:" + dbdvalue + ",响应值:"+resvalue;
FailureMessage += Message;
Failure = true;
log.info(Message);
break;

}

log.info("value:" + res_json_obj.get(key));
}
}

} else {
Message += "接口响应与数据库数据不匹配;";
Message += "响应数据:" + res_json_array + "|数据库查询结果:" + dbd_json_array;
FailureMessage += Message;
Failure = true;
log.info("value:" + res_json_obj.get(key));
break;
}

} else {
FailureMessage = "返回数据为空";
log.info(FailureMessage);
Failure = true;
return;
}
这个脚本有个前提,先建立了返回值的对象,当通过jmeter从数据库获得需要验证的数值的时候,需要指定数据库查询返回值字段名与java对象字段名一致。

遇到Typed variable declaration : Object constructor

发现数据库结果数组如下:

dbd=[{cardType=1, cardTypeText=, cardNo=62260906, bankType=1}]

原因是cardTypeText无值,将cardTypeText赋值可以解决。

相同的代码在eclipse中运行没有问题,但是在jmeter中有问题,可能是对空值的默认处理方法不一样。
---------------------
作者:谁知道丶
来源:CSDN
原文:https://blog.csdn.net/chyo098/article/details/82151019
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/a00ium/p/10372146.html

时间: 2024-08-02 13:08:00

jmeter beanshell Typed variable declaration : Object constructor错误的相关文章

Jmeter BeanShell断言

这篇文章用来记录编写beanshell断言遇到得问题. 问题1:JSONObject not found in namespace 流程:在beanshell下写代码如下: 1 String response_data = prev.getResponseDataAsString(); 2 JSONObject data_obj = new JSONObject(response_data); 3 4 String current_page = data_obj.get("data")

Testing Complex Logic with JMeter Beanshell

BeanShell是最先进的JMeter内置组件之一.JMeter具有丰富的内置插件,可满足性能测试的许多需求.例如,在编写一些复杂的测试时,您可能需要一些额外的脚本.在这种情况下,值得使用Beanshell.在这篇文章中,我们将讨论使用JMeter Beanshell和常见用例测试复杂逻辑.Beanshell具有运行Java代码的功能,并且可以访问JMeter API和在JMeter类路径中加载的外部类. JMeter具有以下启用Beanshell的组件: Beanshell采样器. Bean

JMeter BeanShell示例

翻译:https://blog.trigent.com/jmeter-blog-series-jmeter-beanshell-example 在这个例子中,我们将演示在Apache JMeter中使用BeanShell组件.我们将使用BeanShell脚本语言编写一个简单的测试用例.这些脚本将成为我们将为此示例配置的BeanShell组件的一部分.在我们看看不同BeanShell组件的用法之前,让我们来看看这个概念. 1.简介 Apache JMeter是一个基于Java的开源工具,使您可以对

JMeter博客系列:JMeter BeanShell示例

1.简介 Apache JMeter是一个基于Java的开源工具,使您可以在应用程序上执行功能,负载,性能和回归测试.应用程序可以在Web服务器上运行,也可以是独立的.它支持在包含静态和动态资源的客户端 - 服务器和Web模型上进行测试.它支持各种用于进行测试的协议,包括HTTP,HTTPS,JDBC,FTP,JMS,LDAP,SOAP等. 快速浏览一些功能: 它提供了一个全面的基于GUI的工作台来玩测试.它还允许您在非GUI模式下工作.JMeter也可以移植到服务器上,允许在分布式环境中执行测

android 图片叠加效果——两种方法的简介与内容 ,带解决Immutable bitmap passed to Canvas constructor错误

第一种是通过canvas画出来的效果: [java] view plaincopyprint? public void first(View v) { // 防止出现Immutable bitmap passed to Canvas constructor错误 Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.apple).copy(Bitmap.Config.ARGB_8888, true); Bi

登陆mysql时出现unknown variable &#39;character_set_client=UTF8&#39; 的错误

今天,登陆数据库服务器的时候,出现了下面的错误: 1 [[email protected] app]# mysql -uroot -p 2 mysql: unknown variable 'character-set-client=utf8' 查了下my.cnf的配置文件,是在client段下面配置了这么一个选项,按道理来说,是不会有问题的呀,然后上网google了下,发现: 了解到这个是mysqlbinlog的一个bug. 既然client选项组里允许通过character_set_clien

forward declaration of class 错误

在使用Qt的时候遇到这个错误,查了一下发现,是因为我没有正确的使用前置声明. 1 #ifndef FIRSTPAGE_H 2 #define FIRSTPAGE_H 3 4 #include "ui_dialog.h" 5 //#include <QWizardPage> 6 class QWizardPage; 7 8 class FirstPage : public Ui::Dialog, public QWizardPage 9 { 10 public: 11 Fir

Relevance Between Variable Declaration and Definition in C++

A declaration makes a name known to a programm. A definition creates the assocatied entity. A variable declaration specifies the variable type and name. In addition to specifying the variable type and name, a definition also allocates storage and may

js中的window.open返回object的错误

系统中用javascript中的window.open后,页面返回了一个[object].因为系统的原因,必需使用href="javascript:window.open()"这样的格式.所以只能通过以下办法解决. 解决window.open后返回object的错误 <a href="javascript:void(window.open('','','width=200,height=200'))">window.open()</a> 只在