将自已写的一部分测试代码贴出来,希望大家多提意见

来源:互联网 发布:linux 动态域名解析 编辑:程序博客网 时间:2024/04/29 00:35
公司不能上外网,只有周末回家来这里逛逛,好好整理一下自已的BLOG.
C/S结构,新增一条记录,验证保存后记录的内容是否正确。代码如下:
用WR来进行自动化测试

#数据库连接
rc=db_connect ("stationnet","DSN=wr_test1;UID=sa;PWD=;APP=WinRunner;WSID=local;DATABASE=stationnet",30);

#判断数据库连接是否成功
if (rc !=E_OK)
pause("cannot fail");

#验证处方'000019857'在数据库中是否存在
mm="'000019857'";
a="select get_amount,unit_price,multiple FROM G_RECIPE  where recipe_no=" & mm;
db_execute_query("stationnet",a,record_num);
#pause ("a is  " & a);
total=0;
for (i=0;i<record_num;i++)
{
 value=1;
  for (j=0;j<3;j++)
  {
    val[i,j]=db_get_field_value ("stationnet","#" & i,"#" &j );
    
    value=value*val[i,j];  
   }
 
 tl_step("station",0,"第"& i & "的金额:" & value);
 total=total + value;
}
tl_step("stationnet",0,"总金额为:"&total);

dw_xm="select item_name,unit_price,amount,total from g_outp_bill_item,g_price_list where  g_outp_bill_item.item_code=g_price_list.item_code and cf_code=" & mm;
db_execute_query("stationnet",dw_xm,record_num);
pause ("dw_xm is  " & dw_xm);
xm_total=0;
for(i=0;i<record_num;i++)
{
  for (j=0;j<4;j++)
  {
    xm_item[i,j]=db_get_field_value("stationnet","#" &i,"#" &j);
    
  }
  k=0;
 #pause("xm_item[" &i"] is 项目名称" &xm_item[i,k] &"单价" &xm_item[i,k+1]&"数量" &xm_item[i,k+2]&"金额" &xm_item[i,k+1]);
 tl_step("stationnet",0,"xm_item[" &i"] is 项目名称" &xm_item[i,k] &"单价" &xm_item[i,k+1]&"数量" &xm_item[i,k+2]&"金额" &xm_item[i,k+1]);
 xm_total=xm_total+xm_item[i,k+1];
}
#pause("xm_total is :"&xm_total);
tl_step("stationnet",0,"xm_total is :"&xm_total);
db_disconnect("stationnet");  
db_get_headers("stationnet",field_nu,headers);
tl_step("station",0,"total" & total);