美文网首页
进行Django单元测试

进行Django单元测试

作者: nine_9 | 来源:发表于2018-03-26 18:24 被阅读26次

    Django的单元测试使用python的unittest模块,这个模块使用基于类的方法来定义测试。类名为django.test.TestCase,继承于python的unittest.TestCase。     


    执行目录下所有的测试(所有的test*.py文件):运行测试的时候,测试程序会在所有以test开头的文件中查找所有的test cases(inittest.TestCase的子类),自动建立测试集然后运行测试。 

    1$ python manage.py test

    执行animals项目下tests包里的测试:

     $ python manage.py testanimals.tests

    执行animals项目里的test测试:

    1$ python manage.py testanimals

    单独执行某个test case: 

    1$ python manage.py testanimals.tests.AnimalTestCase

    单独执行某个测试方法: 

    1$ python manage.py testanimals.tests.AnimalTestCase.test_animals_can_speak

    为测试文件提供路径:

    1$ python manage.py testanimals/

    通配测试文件名: 

    1$ python manage.py test--pattern="tests_*.py"

    启用warnings提醒:

    1$ python -Wall manage.py test

    相关文章

      网友评论

          本文标题:进行Django单元测试

          本文链接:https://www.haomeiwen.com/subject/odorcftx.html