Python做单元测试小实例

import sys
#先定义一个函数,这个函数是计算高*宽,并返回计算结果
def test(hight,width):
    return hight*width

#这是程序启动函数入口,给要测试的函数传两个参数(hight,width),得到一个返回结果answer。拿到这个返回结果answer,与预期结果cerrect_answer进行比较,如果一致则打印通过,不一致则打印失败。
if __name__ == '__main__':
    hight=12
    width=2
    cerrect_answer=24
    answer=test(hight,width)
    if answer==cerrect_answer:
        print 'passed'
    else:
        print 'failed'

原文地址:https://www.cnblogs.com/qq738805997/p/5917482.html