django-test

测试系列文章:
https://www.jianshu.com/nb/30319209

django test

django的测试是使用python的单元测试unittest(可以看https://www.jianshu.com/p/1f4bf3e92f5a)。

使用:

  • python manage.py test可以直接测试所有以test开头的文件中查找所有的test cases(inittest.TestCase的子类),自动建立测试集然后运行测试。
  • python manage.py testanimals.tests:执行animals项目下tests包(testanimals)里的测试。
  • python manage.py testanimals:执行animals项目里的test测试。
  • python manage.py testanimals.tests.AnimalTestCase:单独执行某个test case
  • python manage.py testanimals.tests.AnimalTestCase.test_animals_can_speak:单独执行某个测试方法
  • python manage.py testanimals/:为测试文件提供路径
  • python manage.py test--pattern="tests_*.py":通配测试文件名
  • python -Wall manage.py test:启用warnings提醒