import parameterized
import unittest,BeautifulReport
#数据驱动
data = [
['admin','123456',True,'正常登录'],
['admin','1122',False,'冻结用户登录'],
['sdfsdf','1111',False,'黑名单用户登录']
]
data2 = [
['admin','123456',True],
['admin','1122',False],
['sdfsdf','1111',False]
]
def login(user,password):
if user=='admin' and password=='123456':
return True
return False
class LoginTest(unittest.TestCase): # 定义个类,继承unittest
@parameterized.parameterized.expand(data)
def test_login(self,user,password,expect,desc):
self._testMethodDoc = desc # 自己指定用例描述
result = login(user,password)
self.assertEqual(expect,result)
@parameterized.parameterized.expand(data2)
def test_login2(self,user,password,expect):
'''登录'''
result = login(user,password)
self.assertEqual(expect,result)
bf = BeautifulReport.BeautifulReport(unittest.makeSuite(LoginTest))
bf.report(filename='11-17测试报告',description='接口测试报告')
如果想运行同目录下多个python文件的用例
import unittest,BeautifulReport
test_suite = unittest.defaultTestLoader.discover('cases','*.py') # *代表cases目录下所有python文件
bf = BeautifulReport.BeautifulReport(test_suite)
bf.report('report.html','所有用例测试报告')