探索Python在数据库测试中的应用

发表于:2010-3-23 13:32

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

  位于测例与支持库之间的是一个Testloader程序,这个程序完成这几件事情:

  1、 读取根据要执行的测试的配置文件,确定解释器的位置和将要使用哪种驱动;

  2、 读取测试用例的内容,并将对支持类的引用改为对应驱动,比如上面的脚本中的:

  from dbop import * 可能会被改为:from dbop_jdbc import *

  3、 调用对应的解释器执行这个测试用例。

  一个比较简单的例子如下:

cfg.ini:
py_path
=D:\”ACTIVE Python”\python.exe
jy_path
=C:\jython2.2.1\dmjython.bat
ny_path
=C:\pythonnet-2.0-alpha2\pythonnet-2.0-alpha2\python2.5-UCS2\python.exe
#driver
=dotnet
driver
=odbc
#driver
=jdbc
Testloader:
import os
import string
import sys
def exeascript(sc,driver):
    read_script(sc)
    replace_lib_include(sc,driver)
    write_temp_script();
    cmd
= get_executer_path()+ ” ” +temp.py”
    newfile
= file(”temp.py”,”w”)
    newfile.write(all_text);
    newfile.
close()
    os.system(cmd);
    os.remove(”
temp.py”)
mode
=“”
scriptfile
=“”
lstfile
=“”
arg
= sys.argv[1]
tempdriver
=sys.argv[2]
if string.upper(arg[arg.rfind('.')+1:len(arg)])==“PY”:
    mode
=“py”
    scriptfile
= arg
elif string.
upper(arg[arg.rfind('.')+1:len(arg)])==“LST”:
    mode
=“lst”
    lstfile
=arg
jyp
=“”;
nyp
=“”;
cyp
=“”;
ininame
= “cfg.ini”
dataList
=[]
caseList
=[]
gbldriver
=“odbc”
readini(ininame)
for line in dataList:
    getini();
if mode==“lst”:
#
to loop execute testcase
elif mode
==“py”:
exeascript(scriptfile,tempdriver)
else:
    
printNot support”

42/4<1234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号