import unittest
from nose_parameterized import parameterized #用于参数化
def login_k(username,passwd):
def test_login(self):
'''这是登录里面的'''
class login(unittest.TestCase):
def test_login(self):
'''这是登录用例'''
login('kkk',123456)
# self.assertEqual(1,1)
# --------------------------
# def test_login(self):
# '''这是登录用例'''
# login('kkk',123456)
# self.assertEqual(1,1)
# def test_passwd_null(selfself):
# login('kkk','')
#
# def test_login_all_null(self):
# login('','')
#
# def test_login_err(self):
# login('skj','23ssss')
#以上三条用例只是参数不一样,那么我们可以不需要这么麻烦,,将其进行参数化即可
# -----------------------------------------
# 可以像如下这样,进行一个参数化
# s = [
# ['kkk',123456],
# ['kkk',''],
# ['',''],
# ['weew','23sd']
# ]
--------------分割线,下面是用参数化的分割线----------------
import unittest
import HTMLTestRunner
from nose_parameterized import parameterized #用于参数化
def login_k(username,passwd):
if username=='kkk' and passwd==123456:
return True
return False
class My(unittest.TestCase):
@parameterized.expand(
[
['kkk','123456',True],
['kkk','',False],
['','',False],
['ls','12sss',True]
]
)
def test_login(self,username,passwd,hope):
'''这是登录用例'''
res = login_k(username,passwd)
self.assertEqual(res,hope)
suite = unittest.TestSuite() #定义一个测试集合
suite.addTests(unittest.makeSuite(My)) #将类下面的数据都加入到suite套件里面
fw = open('report_kk.html','wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fw,title='kk自动化测试')
runner.run(suite)