本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7615997
建立时间:2006年5月29日




[Python]Python中的单元测试
软件技术

lhwork 发表于 2007/2/2 15:56:11

我用过的testunit有Nunit,Pyunit,Dunit,从易用性来说Pyunit>Nunit>Dunit,这个是由语言特性决定的.PyUnit有不同的实现,python标准库中有一个自带的. 不过说回来,脚本语言unittest的重要性并没有这么大,因为在每个程序文件中随手定义一些测试函数,直接运行就是.这里unittest 模块存在的意义在于能够打印一些profile信息它的使用非常简单,你的测试类必须是unittest.TestCase的子类,然后定义相应的测试函数,只要把函数名称写成testXXX的格式,然后运行unittest.main(),这些测试函数就会被调用.另外,unittest.TestCase提供了一个函数setUp,这个函数会在每个测试函数被调用之前都调用一次,如果需要做一些初始化处理,可以重载这个函数.unittest模块还提供了一些高级功能,可以查看帮助. import unittest class Person:     def age(self):         return 34     def name(self):        return 'bob'    class TestSequenceFunctions(unittest.TestCase):         def setUp(self):         self.man = Person()         print 'set up now'               def test1(self):         self.assertEqual(self.man.age(), 34)       def test2(self):         self.assertEqual(self.man.name(), 'bob')       def test3(self):         self.assertEqual(4+78,23)   if __name__ == '__main__':     unittest.main() 一些相关的链接: A chapter on Unit Testing in Mark Pilgrim’s Dive Into Python unittest module documentation, in the Python Library Reference. UnitTests on the PortlandPatternRepository Wiki, where all the cool ExtremeProgramming kids hang out. Unit Tests in Extreme Programming: A Gentle Introduction. Ron Jeffries espouses on the importance of Unit Tests at 100%. Ron Jeffries writes about the Unit Test in the Extreme Programming practices of C3. PyUnit’s homepage.


阅读全文(1757) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144784822 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号