Python test driven development examples

  • 2020-04-02 14:15:31
  • OfStack

This article is an example of a python test-driven development method, to share with you for your reference. Specific methods are as follows:


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) 

I hope this article has helped you with your Python programming.


Related articles: