文件名为:calculator.py
#计算器类
class Count: def __init__(self,a,b): self.a=int(a) self.b=int(b) #加法 def add(self): return self.a+self.b
测试文件为:test_cal.py
from calculator import Count class TestCount: def test_add(self): j=Count(2,3) add=j.add() assert(5==add),'Inter addtion result error!' except AssertionError as msg: print(msg) else: print('test pass') #执行测试方法; mytest=TestCount() mytest.test_add()
单元测试:test_cal_1.py
from calculator import Count import unittest class TestCount(unittest.TestCase): def setup(self): print("test start") def test_add(self): j=Count(2,3) self.assertEqual(j.add(),4) def tearDown(self): print("test end") if __name__ =='__main__': unittest.main()
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/196865.html