{"title":"Testando em Django","version":"3.1","locale":"pt-br","docname":"topics/testing/index","url":"/pt-br/3.1/topics/testing/","canonical":"https://djangodocs.dev/pt-br/3.1/topics/testing/","summary":"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…","html":"<h1>Testando em Django<a class=\"heading-anchor\" href=\"#testing-in-django\"><span class=\"visually-hidden\">Link para este cabeçalho</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Automated testing is an extremely useful bug-killing tool for the modern\nWeb developer. You can use a collection of tests – a <strong>test suite</strong> – to\nsolve, or avoid, a number of problems:</p>\n<ul class=\"simple\">\n<li><p>When you’re writing new code, you can use tests to validate your code\nworks as expected.</p></li>\n<li><p>When you’re refactoring or modifying old code, you can use tests to\nensure your changes haven’t affected your application’s behavior\nunexpectedly.</p></li>\n</ul>\n<p>Testar uma aplicação web é uma tarefa complexa, porque uma aplicação web é feita por diversas camadas lógicas – vai do nível de uma requisição HTTP, a uma validação e processamento de um formulário, até a renderização de um template. Com a execução de teste em Django e dispondo de diversas utilidades, você pode simular requisições, inserir informações testes, inspecionar saídas de sua aplicação e geralmente verificar se seu código está fazendo o que ele deveria fazer.</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=\"(em 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=\"/pt-br/3.1/topics/testing/overview/\"><span class=\"doc\">Writing and running tests</span></a> document.</p>\n<p>Você pode também usar qualquer <em>outro</em> framework de teste em Python, Django providencia uma API e ferramentas para este tipo de integração. Elas são descritas na <a class=\"reference internal\" href=\"/pt-br/3.1/topics/testing/advanced/#other-testing-frameworks\"><span class=\"std std-ref\">Using different testing frameworks</span></a> seção de <a class=\"reference internal\" href=\"/pt-br/3.1/topics/testing/advanced/\"><span class=\"doc\">Advanced testing topics</span></a>.</p>\n<div class=\"toctree-wrapper compound\">\n<ul>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/pt-br/3.1/topics/testing/overview/\">Writing and running tests</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/pt-br/3.1/topics/testing/tools/\">Testing tools</a></li>\n<li class=\"toctree-l1\"><a class=\"reference internal\" href=\"/pt-br/3.1/topics/testing/advanced/\">Advanced testing topics</a></li>\n</ul>\n</div>","rootId":"testing-in-django","toc":[],"breadcrumbs":[{"docname":"topics/index","title":"Usando o Django","url":"/pt-br/3.1/topics/"}],"prev":{"docname":"topics/files","title":"Managing files","url":"/pt-br/3.1/topics/files/"},"next":{"docname":"topics/testing/overview","title":"Writing and running tests","url":"/pt-br/3.1/topics/testing/overview/"},"formats":{"html":"/pt-br/3.1/topics/testing/","markdown":"/pt-br/3.1/topics/testing.md","json":"/pt-br/3.1/topics/testing.json"},"source":"https://github.com/django/django/blob/stable/3.1.x/docs/topics/testing/index.txt","official":"https://docs.djangoproject.com/pt-br/3.1/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","pt-br","ko","es","el","pl"]}