我正在关注tangowithdjango.com上关于单元测试的django教程。
我的代码是这样的:
from django.test import TestCase
from rango.models import Category
class CategoryMethodTests(TestCase):
def test_ensure_views_are_positive(self):
"""
ensure_views_are_positive
should results True for
categories where views
are zero or positive
"""
cat = Category(name='test',views=-1, likes=0)
cat.save()
self.assertEqual((cat.views >= 0), True)
def test_slug_line_creation(self):
"""
slug_line_creation checks
to make sure that when we
add a category an appropriate
slug line is created
i.e. "Random Category String"
->
"random-category-string"
"""
cat = Category(name='Random Category String')
cat.save()
self.assertEqual(cat.slug, 'random-category-string')
当我跑
时python manage.py test rango
它工作正常,但它说1个测试运行,而实际上我有两个 另外,当我在第二次测试中编写失败的测试时,它不会抛出错误。我在这里缺少什么?