1.unittest 方法执行前
# def setUp(self) -> None: # print('方法执行前执行') # # def tearDown(self) -> None: # print('方法执行后执行一次')
2.unittest 类方法执行前后执行一次
@classmethod def setUpClass(cls) -> None:print('类执行前执行一次')@classmethod def tearDownClass(cls) -> None:print('类执行后执行一次')
url = 'www.baidu.com' data = {'username': '11111','passwrod': '22222' }def testCase01(self):data1 = {'username': '11111'}self.assertDictEqual(data1, data, msg='两个字典不相等') # 判断两部字典是否相当def testCase02(self):flag = Trueself.assertTrue(flag, msg='判断flay是否为true')def testCase03(self):falk1 = 'abc'falk2 = 'abc'self.assertEqual(falk1,falk2,msg='判断两个字符串相当')def testCase04(self):falk3 = 'abcdfghjkk'falk4 = 'adc'self.assertIn(falk4,falk3 ,msg='falk4不在falk3中的字符串')