做过一段时间的接口测试任务,下面把一段接口测试的脚本分享出来:
Action()
{
int rev=0;
web_service_call( "StepName=getPlanData_104",
"SOAPMethod=PlanDataServiceService|PlanDataServicePort|getPlanData",
"ResponseParam=response",
"Service=PlanDataServiceService",
"ExpectedResponse=SoapResult",
"Snapshot=t1450164946.inf",
BEGIN_ARGUMENTS,
"xml:request="
"
"
"
"
"",
END_ARGUMENTS,
BEGIN_RESULT,
"response=Response",
END_RESULT,
LAST);
rev =lr_save_searched_string(lr_eval_string("{Response}"),1500,0,"
if(rev>=0)
{
lr_output_message("交易成功!");
}
else
{
lr_output_message("交易失败,返回值为:%s",lr_eval_string("{result}"));
}
return 0;
}
---------------------------------------------------------------------------------------- Action()
{
//首先调用web_reg_find()这个注册函数,我们接口的正常返回结果都是0
web_reg_find("Search=Body", //定义查找范围
"SaveCount=result", //定义查找计数变量名称
"Text=0
", //定义查找内容
LAST);
//发送请求
web_submit_data("FollowersGetByName",
"Action=http://10.240.248.103:7004/Following/FollowersGetByName.ashx?",
"Method=POST",
ITEMDATA,
//Name后面的值都是接口参数值,可以参考开发人员提供的接口设计文档或者录制脚本获得
//接口的参数值一般都要参数化,尽可能的模拟真是场景
"Name=userid","Value={NewParam}",ENDITEM,
"Name=snsid","Value=6000",ENDITEM,
"Name=username","Value={myUserName}",ENDITEM,
LAST);
//刚才的web_reg_find()注册函数派上用处,可以对结果进行统计
if (atoi(lr_eval_string("{result}")) > 0) //判断如果0
//字符串出现次数大于0
lr_output_message("Log on successful."); //在日志中输出Log on successful
else
//如果出现次数小于等于
lr_error_message("Log on failed"); //在日志中输出Log on failed
return 0;
}
-------------------------------------------------------------------------------------------------------3例------------------
描述:这是一个接口压力测试,调用JAVA编写的一个函数,对返回值进行校验,代码如下:
import lrapi.lr;
import com.lr.test.*;
public class Actions
{
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
String email ="
String address_url ="http://192.168.1.12:8080/interface/index.php/v1/fun?email="+email+";
String result = "";
lr.rendezvous("ReadGO");
lr.start_transaction("FUN");
lr.start_sub_transaction("A","FUN");
lr.start_sub_transaction("B","FUN");
lr.start_sub_transaction("C","FUN");
result = test.getHttpByUrl(address_url);
//结果A
if(!test.getString(result,"NUM").equals("12") && test.getString(result,"Letter").equals("A"))
{
lr.end_transaction("FUN", lr.PASS);
lr.end_sub_transaction("A", lr.PASS);
lr.end_sub_transaction("C", lr.FAIL);
lr.end_sub_transaction("B",lr.FAIL);
lr.error_message(email);
/结果B
}
else if (test.getString(result,"NUM").equals("12") && test.getString(result,"Letter").equals("A"))
{
lr.end_transaction("FUN", lr.PASS);
lr.end_sub_transaction("A", lr.FAIL);
lr.end_sub_transaction("B",lr.PASS);
lr.end_sub_transaction("C", lr.FAIL);
lr.error_message(email);
//结果C
}
else if(test.getString(result,"Letter").equals("C"))
{
lr.end_transaction("FUN", lr.PASS);
lr.end_sub_transaction("A", lr.FAIL);
lr.end_sub_transaction("B",lr.FAIL);
lr.end_sub_transaction("C", lr.PASS);
lr.error_message(email);
}
else
{
lr.error_message(result);
lr.end_transaction("FUN", lr.FAIL);
lr.end_sub_transaction("A", lr.FAIL);
lr.end_sub_transaction("B",lr.FAIL);
lr.end_sub_transaction("C", lr.FAIL);
}
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
问题:
1、如果压力只执行一次(Run until completion),通过事物数和打印email个数一致;如果压力持续执行几分钟,打印email个数会大于通过的事物数,这是怎么回事?
2、一般压力测试只执行一次(Run until completion),还是持续执行一段时间呢?
3、对于我的代码,这样做是否合适呢,有其他更好的方法吗?
4、有跳过前端直接测试Redis处理能力的思路、方法或者例子吗?