python测试驱动开发实例

yipeiwu_com5年前Python基础

本文实例讲述了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程序设计有所帮助。

相关文章

解决python中使用PYQT时中文乱码问题

如题,解决Python中用PyQt时中文乱码问题的解决方法: 在中文字符串前面加上u,如u'你好,世界',其他网上的方法没有多去探究,Python的版本也会影响解决方法,故这里只推荐这种...

Python WEB应用部署的实现方法

Python WEB应用部署的实现方法

本文介绍了Python WEB应用部署的实现方法,分享给大家,具体如下: 使用Apache模块mod_wsgi运行Python WSGI应用 Flask应用是基于WSGI规范的,所以...

python TK库简单应用(实时显示子进程输出)

python TK库简单应用(实时显示子进程输出)

本文介绍python TK库简单应用(实时显示子进程输出),分享给大家,具体如下: #!/usr/bin/python3.5 # -*- coding: UTF-8 -*- im...

Python地图绘制实操详解

Python地图绘制实操详解

网上有很多地图绘制的教程,更多趋向于全国地图或者省级地图,但有时我们需要到县级。闲得慌,今天以贵州省毕节市为例,分享一篇Python县级地图的绘制(遥想当时差点把百度翻了个底朝天),希望...

Python实现句子翻译功能

Python实现句子翻译功能

初入Python,一开始就被她简介的语法所吸引,代码简洁优雅,之前在C#里面打开文件写入文件等操作相比Python复杂多了,而Python打开、修改和保存文件显得简单得多。 1、打开文件...