Django testing: TestCase and SimpleTestCase
Answer: django.test is the testing tools module for Django applications. Django unit tests use the Python standard library unittest module. TestCase subclasses unittest.TestCase and runs each test inside a transaction, which provides isolation.
Examples
from django.test import TestCase
class ItemTests(TestCase):
def test_create(self):
pass
Notes
If tests rely on database access such as creating or querying models, subclass TestCase. SimpleTestCase and TransactionTestCase subclasses have no particular ordering guaranteed among them.
Reference list
Djangounit tests use Python's unittest module.TestCaseruns each test inside a transaction to provide isolation.Teststhat rely on database access should subclass TestCase.
See also
Claims
- id: C1 claim: Django unit tests use Python's unittest module. source: S1 evidence: "Django's unit tests use a Python standard library module"
- id: C2 claim: TestCase runs each test inside a transaction to provide isolation. source: S2 evidence: "runs each test inside a transaction to provide isolation"
- id: C3 claim: Tests that rely on database access should subclass TestCase. source: S2 evidence: "If your tests rely on database access such as creating or querying models"
Sources
- [S1] Writing and running tests. Django docs. https://docs.djangoproject.com/en/5.2/topics/testing/overview/ . License: BSD-3-Clause. Accessed 2026-11-18.
- [S2] overview.txt. Django. https://raw.githubusercontent.com/django/django/stable/5.2.x/docs/topics/testing/overview.txt . License: BSD-3-Clause. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Django docs, Writing and running tests; Django, overview.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Django docs, Writing and running tests; Django, overview.txt. BSD-3-Clause (https://raw.githubusercontent.com/django/django/main/LICENSE). Copyright Django Software Foundation and individual contributors.
Cite this
iinventedlight. 2026. "Django testing: TestCase and SimpleTestCase." iinventedlight Library, iil:note:jgrx8eda, version of 2026-11-18. https://iinventedlight.com/library/notes/django-testing/. License: CC-BY-4.0.
@misc{iil_note_jgrx8eda,
author = {{iinventedlight}},
title = {{Django testing: TestCase and SimpleTestCase}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/django-testing/},
note = {Permanent ID iil:note:jgrx8eda. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- django-testing.table.json (table; CC-BY-4.0)
- django-testing.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/django-testing.md.