使用nosetests对webpy程序做单元测试
来源:互联网 发布:linux如何gzip压缩 编辑:程序博客网 时间:2024/06/05 02:57
ndex.py ---- web.py主文件
#!/usr/bin/env python# -*- coding: utf-8 -*-import weburls = ("/.*", "hello")app = web.application(urls, globals())class hello: def GET(self): return 'Hello, world!'app.wsgifunc()
nose_test.py ---- 测试文件脚本
#!/usr/bin/env python# -*- coding: utf-8 -*-import indexapp = Noneclass TestIndex(object): def setUp(self): print 'init in class' global app self.app = app def test_index(self): print 'test in class' r = self.app.request('/') assert r.status == '200 OK'def setUp(): print 'init in func' global app app = index.appdef test_index(): print 'test in func' global app r = app.request('/') assert r.status == '200 OK'
测试指令
nosetests nose_test.py -v
nosetests参数说明:
- -v:查看测试详细信息
- -s:显示脚本print信息,默认是print的信息是不输出的
nose会查找脚本中 test_命名的函数和Test_命名的类
运行测试脚本时,首先会运行脚本func级别的setUp()函数,
这时候初始化web.py的app
之后会执行class级别的setUp(self)函数,
这时候初始self的app变量为之前初始化的app
#这时候类的__init__()函数是不起作用的
更详细的测试用例可以在test函数中编写,
数据库之类的初始化可以再setUp()函数中编写
如果需要在执行完毕清理资源可以使用tearDown()函数
0 0
- 使用nosetests对webpy程序做单元测试
- nosetests
- 使用DBUnit做单元测试
- 使用xcode5做单元测试
- 使用Nunit做单元测试
- 使用 robolectric 做单元测试
- 使用easymock做单元测试
- Android Studio使用Robolectric对android程序实现单元测试
- Eclipse使用jUnit4对MapReduce程序进行单元测试
- 使用Apache+mod_wsgi部署webpy等python程序
- [Webpy]在webpy中使用jinja2模板
- 使用TestDriven.Net做单元测试
- 使用Qunit做javascript单元测试
- 使用Robolectric做Android单元测试
- 使用MS Test做单元测试
- webpy中使用session
- 简单对项目中的类做单元测试
- webpy
- UVA 11174 Stand in a Line 树形dp+计数
- idea 结合maven开发hibernate实例
- 如何调试手机网页
- 【协议模拟】TCP五层协议信息传输模拟
- 使用百度网盘+Git,把版本控制托管到云端
- 使用nosetests对webpy程序做单元测试
- java/spring/aop
- uity代码总结1
- 从打击App刷榜看苹果的底线
- Map集合中Set<Entry<Character,Integer>>entrySet=map.entrySet();
- [PHP] array_merge解析
- 数据库Sharding的基本思想和切分策略
- <ML In Action系列>k-Nearest Neighbors
- DeepID人脸识别算法之三代