Python 中的 unit test 流程
来源:互联网 发布:西安监测数据造假 编辑:程序博客网 时间:2024/04/29 05:38
Python 中的 unit test 流程
看了看Python中的单元测试流程, 写了个测试代码来看整体的测试流程
总结如下
- 一个 test case 类应该派生自 unittest.TestCase
- 正常的的test case的调用顺序为
- 子类TestCase可以注册自己的清理函数(my_cleanup). 这个清理函数会在teardown之后被调用
def setUp(self): super(MyTestCase, self).setUp() self.addCleanup(self.my_cleanup)
- 单元测试函数名必须以"test_"开始
def test_case_1(self): print("++++ test case 1")
测试的源代码:
from __future__ import print_functionimport unittestdef setUpModule(): print("setUpModule") def tearDownModule(): print("tearDownModule") class MyTestCase(unittest.TestCase): def setUp(self): super(MyTestCase, self).setUp() self.addCleanup(self.my_cleanup) print() print("++++ setup") def tearDown(self): super(MyTestCase, self).tearDown() print("++++ tearDown") raise Exception() def my_cleanup(self): print("++++ my_cleanup") def test_case_1(self): print("++++ test case 1") def test_case_2(self): print("++++ test case 2") @classmethod def setUpClass(cls): print("setUpClass") @classmethod def tearDownClass(cls): print() print("tearDownClass")
这个程序的运行结果:
setUpModulesetUpClass++++ setup++++ test case 1++++ tearDown++++ my_cleanup++++ setup++++ test case 2++++ tearDown++++ my_cleanuptearDownClasstearDownModule
1 0
- Python 中的 unit test 流程
- Python---unit test
- Unit Test中的config file
- Use python for C++ unit/function test
- Python:使用suite执行unit-test用例
- python如何使用unit test 模块
- unit test
- Unit Test
- Unit test
- UNIT TEST
- Unit Test
- Unit Test
- [Python] Use Python to generate Java Unit Test codes automatically
- Unit Test、 UI Test
- python unit test to assert a method calls sys.exit()
- [Python] Do your unit test to ensure code's quality
- 用Python学《微积分B》(Unit Test 1)
- 用Python学《微积分B》(Unit Test 2)
- Matlab图示中的希腊字母和符号等
- 列出类似淘宝网站的分类菜单
- 如何使用KeyChain保存和获取UDID 设备唯一标识
- 撒珍贵的是这个份新格局该房产价格检查过几个几个经济和价格和国际化
- poj3164 Command Network(最小树形图)
- Python 中的 unit test 流程
- Base64编码
- 阿里打假维护电商声誉
- 小黑小波比.在表单div添加事件on,调用JS的事件
- 有关apache mina框架的编码问题
- Android摇一摇功能实现
- android 百度地图 gps数据转换百度经纬度
- java笔试题-> mvc原理 , spring mvc
- java初始化类