单元测试理论之测试策略
自顶向下:从最上层函数开始,逐层开始测试
def sum(a,b): print(a+b) c=jian(a,b) print(c) def jian(x,y): return x-y sum(5,2)
从函数sum开始测试,然后是jian函数,若内部调用函数还未实现,则需要打桩。
def sum(a,b): print(a+b) # c=jian(a,b) # 打桩 c = jian_sub(a,b) print(c) #打桩函数,注意,模拟的函数要与未来实现的函数功能一样。 def jian_sub(a,b): return a-b def jian(x,y): pass sum(5,2)
缺点:成本较大
自底向下: 从最下层开始(周期长)
孤立策略:选择性测试。需要测哪些就用哪个。