本文实例讲述了python测试驱动开发的方法,分享给大家供大家参考。具体方法如下:
import unittest
from main import sample
class sampletest(unittest.testcase):
def setup(self):
print “create a new sample”
self._sample = sample(“b64e5843ca7db8199c405be565fa7f57”)
def teardown(self):
print “destory the sample”
self._sample = none
def test_getvirusnamefromvt(self):
“this md5 has the vt info”
asample = sample(“b64e5843ca7db8199c405be565fa7f57”)
dict_virusname = asample._getvirusnamefromvt()
self.asserttrue(dict_virusname!=none)
def test_getvirusnamefromvt2(self):
“this md5 has not the vt info”
asample = sample(“2b666ffe98e465523e514d2b93b7666a”)
dict_virusname = asample._getvirusnamefromvt ()
self.asserttrue(len(dict_virusname) == 0)
if __name__==”__main__”:
#unittest.main()
suite = unittest.testloader().loadtestsfromtestcase(sampletest)
unittest.texttestrunner(verbosity=2).run(suite)
希望本文所述对大家的python程序设计有所帮助。