python系统测试第七天

关于继承
父类里面有初始化函数,子类创建对象的时候要传参
extend override
什么情况下会用到继承?
在有多个子类,而且每个子类都有很多共同方法的时候需要用到继承
在继承的情况下,子类有父类没有的方法,叫做拓展
在继承的情况下,子类重新写了父类的方法,叫做重写

单元测试

单元测试一般都是开发做的
单元测试测功能:
测试类里面的方法:调用 传参 观察结果===期望结果
一直 pass ,不一致 failed
两个常用的测试方法:unittest pytest
测试用例:序号,步骤,参数,期望结果
执行用例:对比实际结果与期望结果
生成测试报告

class Method:
    def __init__(self,a,b):
        self.a=a
        self.b=b
    def add(self):
        return  self.a+self.b
    def sub(self):
        return  self.a-self.b
    def abs(self):
        return abs(self.a-self.b)
import  unittest  # unittes 是单元测试的一个重要方法
from testing.dianshang0418 import Method
class test(unittest.TestCase):
 # 测试add 方法
 #用例的写法:每一条用例就是一个方法def test__用例描述,
 #必须是test__开头
   def test_add_two(self):
       expected=0
       result=Method(0,0).add() 
       print("00{}".format(result))
       self.assertEqual(expected, result) # assertEqual 是跟期望值来比对是否能够正常运行的




   def test_add_two_fu(self):
     expected=-3
     result = Method(-1, -2).add()
     print("-1,-2 {}" .format(result) )
     self.assertEqual(expected, result)


   def test_add_two_zhengfu(self):
      expected = 1
      result = Method(-2, 3).add()
      print("-2,3, {} ".format(result))
      self.assertEqual(expected, result)

猜你喜欢

转载自blog.csdn.net/guotianxiu1234/article/details/89383185
今日推荐