前面我们完成了测试用例的封装但是却没有正式的启动测试,这是因为我们需要将启动逻辑和测试报告封装在一起实现,代码如下:
import unittest
from BSTestRunner import BSTestRunner
import time
import logging
import sys
path = 'E:\\git\\appium\\autoCese\\'
sys.path.append(path)
test_dir = '../testcase'
report_dir = '../report'
# 加载测试用例
discover = unittest.defaultTestLoader.discover(test_dir, pattern='test_login.py')
# 定义测试报告格式
now = time.strftime("%Y-%m-%d %H_%M_%S")
report_name = report_dir + '/' + now + 'test_report.html'
#运行并生成测试报告
with open(report_name, 'wb') as file:
runner = BSTestRunner(stream=file, title='Kyb test report', description='android app test report')
logging.info('start run testcase...')
runner.run(discover)
这里我们引入了第三方的测试报告样式模块,生成html文件的测试报告,将封装好的测试用例加载到BSRestRunner对象进行执行。
下一步我们将run.py,也就是我们的测试用例执行接口通过.bat批处理文件启动