diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
index 8c11e32..2b193e3 100644
|
a
|
b
|
Here is an example :class:`unittest.TestCase` subclass::
|
| 115 | 115 | |
| 116 | 116 | class AnimalTestCase(unittest.TestCase): |
| 117 | 117 | def setUp(self): |
| 118 | | self.lion = Animal.objects.create(name="lion", sound="roar") |
| 119 | | self.cat = Animal.objects.create(name="cat", sound="meow") |
| | 118 | self.lion = Animal(name="lion", sound="roar") |
| | 119 | self.cat = Animal(name="cat", sound="meow") |
| 120 | 120 | |
| 121 | 121 | def test_animals_can_speak(self): |
| 122 | 122 | """Animals that can speak are correctly identified""" |
| … |
… |
For more details about :mod:`unittest`, see the Python documentation.
|
| 139 | 139 | |
| 140 | 140 | .. _suggested organization: http://docs.python.org/library/unittest.html#organizing-tests |
| 141 | 141 | |
| | 142 | .. warning:: |
| | 143 | |
| | 144 | If your tests rely on database access such as creating or querying models, |
| | 145 | be sure to create your test classes as subclasses of |
| | 146 | :class:`django.test.TestCase` rather than :class:`unittest.TestCase`. |
| | 147 | |
| | 148 | In the example above, we instantiate some models but do not save them to |
| | 149 | the database. Using :class:`unittest.TestCase` avoids the cost of running |
| | 150 | each test in a transaction and flushing the database, but for most |
| | 151 | applications the scope of tests you will be able to write this way will |
| | 152 | be fairly limited, so it's easiest to use :class:`django.test.TestCase`. |
| | 153 | |
| 142 | 154 | Writing doctests |
| 143 | 155 | ---------------- |
| 144 | 156 | |
| … |
… |
This convenience method sets up the test database, and puts other
|
| 343 | 355 | Django features into modes that allow for repeatable testing. |
| 344 | 356 | |
| 345 | 357 | The call to :meth:`~django.test.utils.setup_test_environment` is made |
| 346 | | automatically as part of the setup of `./manage.py test`. You only |
| | 358 | automatically as part of the setup of ``./manage.py test``. You only |
| 347 | 359 | need to manually invoke this method if you're not using running your |
| 348 | 360 | tests via Django's test runner. |
| 349 | 361 | |
| … |
… |
attribute::
|
| 1385 | 1397 | |
| 1386 | 1398 | def test_my_stuff(self): |
| 1387 | 1399 | # Here self.client is an instance of MyTestClient... |
| | 1400 | call_some_test_code() |
| 1388 | 1401 | |
| 1389 | 1402 | .. _topics-testing-fixtures: |
| 1390 | 1403 | |