python测试驱动开发实例

yipeiwu_com6年前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开发环境搭建

详解python开发环境搭建

虽然网上有很多python开发环境搭建的文章,不过重复造轮子还是要的,记录一下过程,方便自己以后配置,也方便正在学习中的同事配置他们的环境。 1.准备好安装包 1)上python官网下载...

Python 使用元类type创建类对象常见应用详解

本文实例讲述了Python 使用元类type创建类对象。分享给大家供大家参考,具体如下: type("123") 可以查看变量的类型;同时 type("类名",(父类),{类属性:值,类...

Python-Tkinter Text输入内容在界面显示的实例

使用Tkinter(py2.7)text文本框中输入内容在界面中显示–较为规整的代码: import Tkinter as tk class Window: def __init...

pycharm 批量修改变量名称的方法

pycharm 批量修改变量名称的方法

当代码已经写得差不多,发现某个变量名需要修改,但代码中很多地方都有该变量,一一修改太麻烦了,在不同的情景下,可以采取更加简便的方法,如下介绍: 方法一:rename方法 S1 把光标移动...

python调用新浪微博API项目实践

python调用新浪微博API项目实践

因为最近接触到调用新浪微博开放接口的项目,所以就想试试用python调用微博API。 SDK下载地址:http://open.weibo.com/wiki/SDK 代码不多十几K,完全可...