Automated testing is an extremely useful bug-killing tool for the modern web developer. You can use a collection of tests -- a test suite -- to solve, or avoid, a number of problems:
Testing a web application is a complex task, because a web application is made of several layers of logic -- from HTTP-level request handling, to form validation and processing, to template rendering. 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.
在 Django 中编写测试的首选方式是使用 Python 标准库中内置的 unittest
模块。这一点在 编写并运行测试 文档中有详细介绍。
你也可以使用 另一个 Python 测试框架;Django 提供了用于这种集成的 API 和工具。这在 进阶测试主题 的 使用不同的测试框架 章节中有介绍。
9月 22, 2023