How do unittest parameterized it?
If the argument is that we are different, we just need a list which parameters are written at the time of writing the case, then this case can cycle to execute.
There is a unittest module parameterized, cycling can help us, do not need to write their own cycle, direct pip install parameterized installed.
For example: a landing case
import parameterized import unittest,BeautifulReport data = [ [ ' ADMIN ' , ' 123456 ' , True], # third column represents an expected result [ ' ADMIN ' , ' 1122 ' , False], ['sdfsdf','1111',False] ] data1 = [ [ ' ADMIN ' , ' 123456 ' , True, ' normal landing ' ], # fourth column shows the description [ ' ADMIN ' , ' 1122 ' , False, ' freeze user login ' ], [ ' Sdfsdf ' , ' 1111 ' , False, ' blacklist user login ' ] ] def login(user,password): if user=='admin' and password=='123456': return True return False class LoginTest(unittest.TestCase): @parameterized.parameterized.expand(data) DEF test_login (Self, User, password, Expect): '' ' login ' '' # plus' '' in the test report will display described Result = Login (User, password) self.assertEqual(expect,result) @parameterized.parameterized.expand(data1) def test_login1(self,user,password,expect,desc): self._testMethodDoc = desc # own designated with like display as described in Example Result = Login (User, password) self.assertEqual(expect,result) bf=BeautifulReport.BeautifulReport(unittest.makeSuite(LoginTest)) bf.report (filename = ' 11-17 test report ' , Description = " Interface Test Report ' )
Results: shows two kinds of patterns used in the embodiment described, in which 123 is specified with the embodiment described, 456 is the default style.