Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
84d8b247
Kaydet (Commit)
84d8b247
authored
May 15, 2013
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #20165 - Updated testing example to use django.test.TestCase.
Thanks Lorin Hochstein.
üst
4ecc6da2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
overview.txt
docs/topics/testing/overview.txt
+16
-12
No files found.
docs/topics/testing/overview.txt
Dosyayı görüntüle @
84d8b247
...
...
@@ -46,20 +46,24 @@ module defines tests using a class-based approach.
.. _unittest2: http://pypi.python.org/pypi/unittest2
Here is an example :class:`unittest.TestCase` subclass::
Here is an example which subclasses from :class:`django.test.TestCase`,
which is a subclass of :class:`unittest.TestCase` that runs each test inside a
transaction to provide isolation::
from django.
utils import unittest
from django.
test import TestCase
from myapp.models import Animal
class AnimalTestCase(
unittest.
TestCase):
class AnimalTestCase(TestCase):
def setUp(self):
self.lion = Animal
(name="lion", sound="roar")
self.cat = Animal
(name="cat", sound="meow")
Animal.objects.create
(name="lion", sound="roar")
Animal.objects.create
(name="cat", sound="meow")
def test_animals_can_speak(self):
"""Animals that can speak are correctly identified"""
self.assertEqual(self.lion.speak(), 'The lion says "roar"')
self.assertEqual(self.cat.speak(), 'The cat says "meow"')
lion = Animal.objects.get(name="lion")
cat = Animal.objects.get(name="cat")
self.assertEqual(lion.speak(), 'The lion says "roar"')
self.assertEqual(cat.speak(), 'The cat says "meow"')
When you :ref:`run your tests <running-tests>`, the default behavior of the
test utility is to find all the test cases (that is, subclasses of
...
...
@@ -80,11 +84,11 @@ For more details about :mod:`unittest`, see the Python documentation.
be sure to create your test classes as subclasses of
:class:`django.test.TestCase` rather than :class:`unittest.TestCase`.
In the example above, we instantiate some models but do not save them to
t
he database. Using :class:`unittest.TestCase` avoids the cost of running
each test in a transaction and flushing the database, but for mo
st
applications the scope of tests you will be able to write this way will
be fairly limited, so it's easiest to use :class:`django.test.TestCase`
.
Using :class:`unittest.TestCase` avoids the cost of running each test in a
t
ransaction and flushing the database, but if your tests interact with
the database their behavior will vary based on the order that the te
st
runner executes them. This can lead to unit tests that pass when run in
isolation but fail when run in a suite
.
.. _running-tests:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment