在一个已经注册了的app里想测试model,写了如下测试:
# -*- coding:utf-8 -*-
from django.test import TestCase
# Create your tests here.
from group.models import Group
class GroupTestCase(TestCase):
def setUp(self):
print "开始存储数据"
Group.objects.create(group_name="lion", group_info="roar")
但是运行的结果确实这样的,显示没有测试项,还需要什么测试么?
> zy@zy:~/code/python/app/git/app/webcode$ python manage.py test
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
- 先在
settings.py
里INSTALLED_APPS
确定是否安装了该app
- 测试文件要以
tests.py
命名
A conventional place for an application’s tests is in the application’s tests.py file; the testing system will automatically find tests in any file whose name begins with test.
参考:
https://docs.djangoproject.com/en/1.7/intro/tutorial05/#create-a-test-to-expose-the-bug
测试方法要以 test 开头