标签:lis highlight assert bsp obj tin from stc cas
# unittest单元测试 import unittest from class_demo import Car class TestCar(unittest.TestCase): ‘‘‘测试Car类‘‘‘ def setUp(self): ‘‘‘初始化数据‘‘‘ self.car_obj = Car(‘Audi‘, ‘A6‘, 2017) def test_set_odometer(self): ‘‘‘测试Car类的set_odometer方法‘‘‘ self.car_obj.set_odometer(1000) self.assertEqual(1000, self.car_obj.odometer) def test_set_odometer_wrong(self): self.car_obj.set_odometer(5000) self.assertEqual(1000, self.car_obj.odometer)
断言的方法:
assertEqual(a, b) 核实a = b assertNotEqual(a, b) 核实a != b assertTrue(x) 核实x为True assertFalse(x) 核实x为False assertIn(item, list) 核实item在list中 assertNotIn(item, list) 核实item不在list中
标签:lis highlight assert bsp obj tin from stc cas
原文地址:http://www.cnblogs.com/gongxr/p/7225506.html