{"title":"Django におけるテスト","version":"3.2","locale":"ja","docname":"topics/testing/index","url":"/ja/3.2/topics/testing/","canonical":"https://djangodocs.dev/ja/3.2/topics/testing/","summary":"自動化テストは、モダンなウェブ開発者にとってバグを殺すために非常に役に立つツールです。テストのコレクション、 test suite を使うことで、次のような数々の問題を解決したり避けることができます。 新しいコードを書いている時、テストを使えば、自分が書いたコードが期待通りに動作するかどうか確かめることができる。…","html":"<h1>Django におけるテスト<a class=\"heading-anchor\" href=\"#testing-in-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>自動化テストは、モダンなウェブ開発者にとってバグを殺すために非常に役に立つツールです。テストのコレクション、 <strong>test suite</strong> を使うことで、次のような数々の問題を解決したり避けることができます。</p>\n<ul class=\"simple\">\n<li><p>新しいコードを書いている時、テストを使えば、自分が書いたコードが期待通りに動作するかどうか確かめることができる。</p></li>\n<li><p>古いコードのリファクタリングや修正をしている時、テストを使うことで、自分の行った変更が思ってもないような仕方でアプリケーションの動作を変更してしまわないことを保証できる。</p></li>\n</ul>\n<p>Web アプリケーションのテストは複雑なタスクです。なぜならば、Web アプリケーションには複数のロジックのレイヤーが存在するからです。HTTP レベルのリクエストのハンドリングから、フォームの検証と処理、テンプレートのレンダリングなどです。しかし、Django のテスト実行フレームワークと各種ユーティリティを使えば、リクエストをシミュレートしたり、テストデータを挿入したり、アプリケーションの出力を検査したり、さらに一般に、書いたコードが期待通りの動作をするかどうかを検証することができます。</p>\n<p>The preferred way to write tests in Django is using the <a class=\"reference external\" href=\"https://docs.python.org/3/library/unittest.html#module-unittest\" title=\"(in Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\"><span class=\"pre\">unittest</span></code></a> module\nbuilt-in to the Python standard library. This is covered in detail in the\n<a class=\"reference internal\" href=\"/ja/3.2/topics/testing/overview/\"><span class=\"doc\">テストを書いて実行する</span></a> document.</p>\n<p><em>その他</em> どんな Python テストフレームワークでも利用できます。Django は、この種のインテグレーションのためのAPI や各種ツールを提供しているからです。これらについては、 <a class=\"reference internal\" href=\"/ja/3.2/topics/testing/advanced/\"><span class=\"doc\">Advanced testing topics</span></a> の <a class=\"reference internal\" href=\"/ja/3.2/topics/testing/advanced/#other-testing-frameworks\"><span class=\"std std-ref\">Using different testing frameworks</span></a> セクションで説明しています。</p>\n<div class=\"toctree-wrapper compound\">\n<ul>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/ja/3.2/topics/testing/overview/\">テストを書いて実行する</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/ja/3.2/topics/testing/tools/\">テストツール</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/ja/3.2/topics/testing/advanced/\">Advanced testing topics</a></li>\n</ul>\n</div>","rootId":"testing-in-django","toc":[],"breadcrumbs":[{"docname":"topics/index","title":"Django を使う","url":"/ja/3.2/topics/"}],"prev":{"docname":"topics/files","title":"ファイルの管理","url":"/ja/3.2/topics/files/"},"next":{"docname":"topics/testing/overview","title":"テストを書いて実行する","url":"/ja/3.2/topics/testing/overview/"},"formats":{"html":"/ja/3.2/topics/testing/","markdown":"/ja/3.2/topics/testing.md","json":"/ja/3.2/topics/testing.json"},"source":"https://github.com/django/django/blob/stable/3.2.x/docs/topics/testing/index.txt","official":"https://docs.djangoproject.com/ja/3.2/topics/testing/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}