在单元测试方面,Django继承python的unittest.TestCase实现了自己的django.test.TestCase,编写测试用例通常从这里开始。测试代码通常位于app的tests.py文件中
##为何要在django中使用test
-
When you’re writing new code, you can use tests to validate your code works as expected.
-
When you’re refactoring or modifying old code, you can use tests to ensure your changes haven’t affected your application’s behavior unexpectedly.
-
With Django’s test-execution framework and assorted utilities, you can simulate requests, insert test data, inspect your application’s output and generally verify your code is doing what it should be doing.
##Writing and running tests
|
|
你可以有几种方式运行单元测试:
- python manage.py test:执行所有的测试用例
- python manage.py test app_name, 执行该app的所有测试用例
- python manage.py test app_name.case_name: 执行指定的测试用例
##Testing tools:Overview and a quick example
|
|
##The request factory
|
|
##unit test file upload in django
|
|
##参考资料
文章作者 种瓜
上次更新 2014-07-31