Django におけるテスト

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.

The preferred way to write tests in Django is using the unittest module built-in to the Python standard library. This is covered in detail in the テストを書いて実行する document.

その他 どんな Python テストフレームワークでも利用できます。Django は、この種のインテグレーションのためのAPI や各種ツールを提供しているからです。これらについては、 Advanced testing topicsUsing different testing frameworks セクションで説明しています。