Python 官方文档:入门教程 => 点击学习
待测试的类:class Request: url = "" method = "" paras = {} def __init__(self,url): self.url = url se
待测试的类:
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)
==============================
运行结果:
--结束END--
本文标题: python unittest初探
本文链接: https://lsjlt.com/news/185458.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0