本文实例讲述了python之pyunit单元测试,与erlang eunit单元测试很像,分享给大家供大家参考。具体方法如下:
1.widget.py文件如下:
python内部自带了一个单元测试的模块,pyUnit也就是我们说的:unittest;本文档主要讲述的是python unittest基本介绍;感兴趣的朋友可以过来看看
0
立即学习“Python免费学习笔记(深入)”;
class Widget:
def __init__(self, size = (40, 40)):
self.size = size
def getSize(self):
return self.size
def resize(self, width, height):
if width
raise ValueError, "illegal size"
self.size = (width, height)
def dispose(self):
passDefaultTestCase
2. auto.py文件如下:
立即学习“Python免费学习笔记(深入)”;
3.执行结果如下:
[code]jobin@jobin-desktop:~/work/python/py_unit$ python auto.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
jobin@jobin-desktop:~/work/python/py_unit$ python auto.py
F
======================================================================
FAIL: testSize (__main__.WidgetTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "auto.py", line 15, in testSize
self.assertEqual(self.widget.getSize(), (50, 40))
AssertionError: (40, 40) != (50, 40)
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)
jobin@jobin-desktop:~/work/python/py_unit$[/code]
希望本文所述对大家的Python程序设计有所帮助。
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号