位于测例与支持库之间的是一个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: print “Not support” |