我创建了一个test.py模块,里面填充了
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from forum.models import *
class SimpleTest(TestCase):
def setUp(self):
u = User.objects.create_user("ak", "ak@abc.org", "pwd")
Forum.objects.create(title="forum")
Site.objects.create(domain="test.org", name="test.org")
def content_test(self, url, values):
"""Get content of url and test that each of items in `values` list is present."""
r = self.c.get(url)
self.assertEquals(r.status_code, 200)
for v in values:
self.assertTrue(v in r.content)
def test(self):
self.c = Client()
self.c.login(username="ak", password="pwd")
self.content_test("/forum/", ['<a href="/forum/forum/1/">forum</a>'])
....
我把它放在了我的应用程序文件夹中。 当我运行测试时,
python manage.py test forum
创建测试数据库后,我得到了一个答案:“Ran 0 tests in 0.000s”。
我做错了什么?
附言: 这是我的项目层次结构:
MyProj:
forum (it's my app):
manage.py
models.py
views.py
tests.py
...
我把test.py重命名为tests.py。Eclipse认为这个模块属于测试,但是结果仍然显示“在0.000秒内运行了0个测试”