从数据库取值和响应值做比较,使用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
版权声明:本文为博主原创文章,转载请附上博文链接!

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

  1. jmeter报错:响应数据HTTP Status 500 & 后台日志Typed variable declaration : Object constructor

    今天在测试文件下载接口,发现在测试单个文件下载1次时,文件成功下载.但是在测试单个文件并发下载50次时,Jmeter报错了,后台服务器tomcat竟然没有发现报错信息. Jmeter响应信息报错: H ...

  2. Jmeter BeanShell断言

    这篇文章用来记录编写beanshell断言遇到得问题. 问题1:JSONObject not found in namespace 流程:在beanshell下写代码如下: 1 String resp ...

  3. jmeter beanshell postprocessor 使用

    String newtoken=bsh.args[0];print(newtoken);${__setProperty(newtoken,${token},)}; String newcompanyI ...

  4. Testing Complex Logic with JMeter Beanshell

    BeanShell是最先进的JMeter内置组件之一.JMeter具有丰富的内置插件,可满足性能测试的许多需求.例如,在编写一些复杂的测试时,您可能需要一些额外的脚本.在这种情况下,值得使用Beans ...

  5. jmeter beanshell

    //获取返回数据 String json = prev.getResponseDataAsString(); ///加入变量vars.put("restr",json); //获取 ...

  6. JMeter BeanShell示例

    翻译:https://blog.trigent.com/jmeter-blog-series-jmeter-beanshell-example 在这个例子中,我们将演示在Apache JMeter中使 ...

  7. JMeter博客系列:JMeter BeanShell示例

    1.简介 Apache JMeter是一个基于Java的开源工具,使您可以在应用程序上执行功能,负载,性能和回归测试.应用程序可以在Web服务器上运行,也可以是独立的.它支持在包含静态和动态资源的客户 ...

  8. Relevance Between Variable Declaration and Definition in C++

    A declaration makes a name known to a programm. A definition creates the assocatied entity. A variab ...

  9. Object constructor

    1. Object is an instance of Function.2. Object does not have a property called constructor so when w ...

随机推荐

  1. 【LeetCode】036. Valid Sudoku

    题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  2. Navicat生成数据库结构同步SQL

    作为一个苦逼的技术男,在做开发的时候经常会遇见程序版本升级,数据库结构变化.我们需要一个快捷的方式让客户尽快从旧版本数据库结构更新至新版本数据库结构.如果每做一次改动我们就记录一下当然是好事,但是万一 ...

  3. 串口编程3:使用串口读取GPS信息

    关于GPS的使用,参考. 本文主要参考的博客,在此表示感谢!!! 主函数 主函数gps_main.c,这里便涉及到了串口的打开,读操作,以及调用了串口设置函数: #include <stdio. ...

  4. 开发框架:AdminLTE

    ylbtech-开发框架:AdminLTE 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部 1. 2. 5.返回顶部 1. https://adminlte.io 2.   6.返 ...

  5. 插曲一--记《数据结构与问题求解(Java语言版)(第4版)》翻译问题

    在该书的527页中18.6理论题中,书中这样写道"完全结点是指每个结点都有两个孩子.证明,完全二叉树的结点数加1等于叶子树." 初看此题目,本人觉得很纳闷,再细细想之,发现似乎是个 ...

  6. kvm ip查看

    1.virsh --list(查看有哪些服务器) 2.virsh dumpxml 虚拟机名称 查看服务器对应的mac地址 3.然后再宿主机上arp -a 查看对应的mac地址对应的ip

  7. Python 图像识别入门篇

    一.安装Python依赖 pip install pytesseract pyocr pillow Image pip安装:https://www.cnblogs.com/Javame/p/10918 ...

  8. 我推荐的一些C\C++书籍

    原文链接: 我推荐的一些C\C++书籍 人们常常问我有什么C++和编程的书籍推荐,也许是因为我在PowerDNS有一个关于"编写可读性良好的C++代码"的演讲.这篇博文可以作为我对 ...

  9. Java探索之旅(14)——文本I/O与读写

    1文件类File    ❶封装文件或路径的属性.不包括创建和读写文件操作.File实例并不会实际创建文件.不论文件存在与否,可以创建任意文件名的实例.两种实例创建方式如下:               ...

  10. SAP 销售订单中采购标识无法修改

    VA03中的销售订单第四个物料没有ZA选项, 错误提示:计划行类别ZA未定义 原因: MM03中的 MRP2---采购类型未被定义