因为loadrunner原生未提供针对mysql测试的功能
国内网络上流传的都是ODBC连接mysql进行性能测试,过程较为繁琐
而LR本身推荐的是使用提供的dll库或者自行编写dll库进行测试。
只要能在网上找到支持自编写dll库的license即可
本文方法参考的主要是Bish.co.uk论坛,有mysql,php和loadrunner板块,
使用它们编写的mysql链接库
---–待测试库环境准备--------
GRANT ALL PRIVILEGES ON *.* TO'root'@'windowsIP'
IDENTIFIED BY'root'WITHGRANTOPTION;
配置好测试数据库和表
-----–LoadRunner运行库准备-------
a.解压MySQL LoadRunner libraries.zip版本1 版本2 中的文件至LR安装目录
b.在LR的vuser脚本的init中加入实例信息
#include "Ptt_Mysql.h" #define MYSQLSERVER "192.168.2.5" #define MYSQLUSERNAME "root" #define MYSQLPASSWORD "root" #define MYSQLDB "tpch_1" #define MYSQLPORT "5029" |
c.在action脚本中 每个sql语句前加入
lr_load_dll("libmysql.dll");
-------–vu脚本编写方法,c语言--------–
//action中加入 char chQuery[128]; MYSQL *Mconn; //将sql语句保存在 char中 lr_load_dll("libmysql.dll"); //每个sql前加入读取dll库 Mconn = lr_mysql_connect(MYSQLSERVER, MYSQLUSERNAME, MYSQLPASSWORD, MYSQLDB, atoi(MYSQLPORT)); //从init的define中读取连接参数 sprintf(chQuery, "select N_NATIONKEY,N_NAME,N_REGIONKEY from nation limit 3;"); lr_mysql_query(Mconn, chQuery); //在输出中打印语句,调用dll中的lr_mysql_query方法执行语句 lr_save_string(row[0][0].cell, "sN_NATIONKEY"); lr_save_string(row[1][0].cell, "sN_NAME"); lr_save_string(row[2][0].cell, "sN_REGIONKEY"); //结果集要保存到多维数组中也可以直接忽略输出 lr_output_message(lr_eval_string("N_NATIONKEY: {sN_NATIONKEY}; N_NAME: {sN_NAME}; N_REGIONKEY Description:{sN_REGIONKEY}")); lr_save_string(row[0][1].cell, "sN_NATIONKEY"); lr_save_string(row[1][1].cell, "sN_NAME"); lr_save_string(row[2][1].cell, "sJobDesc"); lr_output_message(lr_eval_string("N_NATIONKEY: {sN_NATIONKEY}; N_NAME: {sN_NAME}; N_REGIONKEY Description:{ //vu_end中加入 lr_mysql_disconnect(Mconn); //断开连接 自己录制脚本例子
#include "Ptt_Mysql.h" #define MYSQLSERVER "192.168.20.67" #define MYSQLUSERNAME "root" #define MYSQLPASSWORD "111111" #define MYSQLDB "mysql" #define MYSQLPORT "3306" MYSQL *Mconn; vuser_init(){ lr_load_dll("libmysql.dll"); Mconn=lr_mysql_connect(MYSQLSERVER,MYSQLUSERNAME,MYSQLPASSWORD,MYSQLDB,atoi(MYSQLPORT)); return 0; } Action() { char chQuery[128]; //sprintf(chQuery,"SELECT `HOST`, `USER`, `PASSWORD` FROM user1;"); lr_mysql_query(Mconn,chQuery); lr_save_string(row[0][0].cell,"HOST"); lr_save_string(row[1][0].cell,"USER"); lr_save_string(row[2][0].cell,"PASSWORD"); lr_output_message(lr_eval_string("HOST: {HOST}; USER: {USER};PASSWORD:{PASSWORD}")); } vuser_end() { lr_mysql_disconnect(Mconn); return 0; } |
版权声明:本文出自 juiwo 的51Testing软件测试博客: http://www.51testing.com/?37338 原创作品,转载时请务必以超链接形式标明本文原始出处、作者信息和本声明,否则将追究法律责任。 |