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 pandas dataframe 按列或者按行合并的方法

concat 与其说是连接,更准确的说是拼接。就是把两个表直接合在一起。于是有一个突出的问题,是横向拼接还是纵向拼接,所以concat 函数的关键参数是axis 。 函数的具体参数是:...

python3利用Socket实现通信的方法示例

python3利用Socket实现通信的方法示例

参考于: python cs架构实现简单文件传输 原文中程序运行有误,在此做修改与解释,如下: 功能说明: 共2个py文件分别为server和client端,采用socket进行通信。...

Python完全识别验证码自动登录实例详解

1、直接贴代码 #!C:/Python27 #coding=utf-8 from selenium import webdriver from selenium.webdri...

使用Python更换外网IP的方法

在进行数据抓取时,经常会遇到IP被限制的情况,常见的解决方案是搭建代理IP池,或购买IP代理的服务。除此之外,还有一个另外的方法就是使用家里的宽带网络进行抓取。由于家里的宽带每次断开重新...

python 把列表转化为字符串的方法

列表转化为字符串 如下所示: >>> list1=['ak','uk',4] >>> list2=[str(i) for i in list1]...