python unittest初探
待测试的类:
class Request:
url = ""
method = ""
paras = {}
def __init__(self,url):
self.url = url
self.method = "post"
self.paras = {}
def setPincode(self,pincode):
self.addParas("pincode",pincode)
def getPincode(self):
return self.paras.get("pincode")
def addParas(self,key,value):
if (self.paras.has_key(key)):
del self.paras[key]
self.paras[key] = value
==============================================
测试类:
import unittest
from Request import *
class MyTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
print "--------------End!"
pass
def test_Request(self):
self.request = Request("http://www.baidu.com")
self.request.setPincode("pincode1")
self.request.addParas("pincode","parauuuuuuuuuuuuuu1")
self.assertEqual(self.request.getPincode(),"parauuuuuuuuuuuuuu1")
for k,v in self.request.paras.items():
print k,v
def test_something(self):
self.assertEqual(False, False)
print "test_something1"
def suite():
suite = unittest.TestSuite()
print "1"
suite.addTest(unittest.makeSuite(MyTestCase,"test"))
print "2"
return suite
if __name__ == '__main__':
# unittest.main()
suiteTest = suite()
runner = unittest.TextTestRunner()
runner.run(suiteTest)
==============================
运行结果:
..
2
----------------------------------------------------------------------
pincode parauuuuuuuuuuuuuu1
Ran 2 tests in 0.001s
--------------End!
test_something1
OK
--------------End!
Process finished with exit code 0
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341