Brief talk for django test

来源:互联网 发布:家庭媒体中心软件 编辑:程序博客网 时间:2024/06/05 09:43

Core tasks

(1)writing tests
(2)running tests

Writing

(a)TestCase class
django.test.TestCase as subclass from unittest.TestCase
(b) Mock
situation: patch out external function call in view
notes: where to patch is where it is used or it is looked up. that is, that
function to be mocked

(b.1)patch as decorator or context manager
makes it easy to mock classes or objects in a module under test.

Running

(a)coverage

Code coverage describes how much source code has been tested.

(a.1)installation by pip (c extension required in linux)
pip install coverage
(a.2)common commands

coverage run --source=SRC1,SRC2,... manage.py test test_label #
coverage report -m

for example, assume that working dir is just under django project or same level with app to be test,
coverage run --source=./some_app manage.py test ./some_app/
, where source option is used for limiting report statistic range

原创粉丝点击