今天開始研究python的unittest模塊,爲咱們當前作的項目定製測試方案,包括unittest和自動化流程測試。python
python的unittest的基本使用方法以下:測試
#!/usr/bin/env python #encoding: utf-8 ######################################################################## class myclass: """""" #---------------------------------------------------------------------- def __init__(self): """Constructor""" def sum(self, x, y): return x+y def sub(self, x, y): return x-y
#!/usr/bin/env python #encoding: utf-8 import unittest import code1 import time class mytest(unittest.TestCase): ##初始化工做 def setUp(self): print "test start....." self.tclass = code1.myclass() def tearDown(self): print "test stop......" def testsum(self): self.assertEqual(self.tclass.sum(1,2), 3, 'test sum fail') def testsub(self): self.assertEqual(self.tclass.sub(2,1), 1, 'test sub fail') if __name__ == '__main__': print dir(unittest) print '\r\n' unittest.main()