Django的单元测试
2016-06-08 17:06
344 查看
1、单元测试框架
django-unittest
https://docs.djangoproject.com/en/1.9/topics/testing/overview/#speeding-up-the-tests
自动生成测试数据库时候,要注意编码问题,特别是数据库中存储了汉字信息。 需要在
2、模拟数据
有两种办法,其一是通过api去手动生成;其二是通过fixture,让测试框架自动导数据到测试数据库中去
方法一,多用 model.mommy开源包
方法二,可能很多场合应该更适合,特别是数据表大的时候
https://docs.djangoproject.com/en/1.9/topics/testing/tools/#fixture-loading
注意导出真实数据库的auth数据时候,要用如下命令,具体原因:
3、模拟浏览器
https://realpython.com/blog/python/testing-in-django-part-1-best-practices-and-examples/
https://realpython.com/blog/python/testing-in-django-part-2-model-mommy-vs-django-testing-fixtures/
https://realpython.com/blog/python/django-1-6-test-driven-development/
django-unittest
https://docs.djangoproject.com/en/1.9/topics/testing/overview/#speeding-up-the-tests
自动生成测试数据库时候,要注意编码问题,特别是数据库中存储了汉字信息。 需要在
"default": { "ENGINE": "django.db.backends.mysql", "NAME": "webplatform", "USER": "root", "PASSWORD": "123456", "HOST": "127.0.0.1", "PORT": "3306", 'TEST_CHARSET': "utf8", 'TEST_COLLATION': "utf8_general_ci", },
2、模拟数据
有两种办法,其一是通过api去手动生成;其二是通过fixture,让测试框架自动导数据到测试数据库中去
方法一,多用 model.mommy开源包
方法二,可能很多场合应该更适合,特别是数据表大的时候
https://docs.djangoproject.com/en/1.9/topics/testing/tools/#fixture-loading
注意导出真实数据库的auth数据时候,要用如下命令,具体原因:
python manage.py dumpdata auth --exclude auth.Permission --exclude contenttypes --indent=4 > auth.json
3、模拟浏览器
https://realpython.com/blog/python/testing-in-django-part-1-best-practices-and-examples/
https://realpython.com/blog/python/testing-in-django-part-2-model-mommy-vs-django-testing-fixtures/
https://realpython.com/blog/python/django-1-6-test-driven-development/
相关文章推荐
- Golang 中"泛型"的支持
- Django 实现简单的文件上传
- Django 实现简单的文件上传
- django 过滤器 、日期格式化参数
- (4.2.30)Google开源的FlexboxLayout
- windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境
- mongostat
- I'm going to bloging!!
- 快捷方式
- golang: Go语言:简介
- Google VR Concepts (2)- VR View
- CEPH CRUSH algorithm source code analysis
- 如何使用sshgo
- Ubuntu上安装Robomongo及添加到启动器
- left edge algorithm.
- Django框架下的HelloWorld
- 在Google Chrome中快速解除网页屏蔽鼠标右键、复制等限制
- Introduction to Algorithms-Lecture2数学课
- CF 5A Chat Server's Outgoing Traffic(字符串模拟)
- 认识Zygote