我正在学习 Django 休息框架。我写了一个这样的简单测试:
from rest_framework import status
from rest_framework.test import APITestCase
class ClinicTestCase(APITestCase):
def getList(self):
factory = APIRequestFactory()
request = factory.get('/Clinic/')
self.assertEqual(response.status_code, status.OK)
我的 api 为该请求返回空的 json 数组。我不知道的是,我如何运行此测试?
当我使用这个命令时:
python manage.py test
我明白了
Ran 0 tests in 0.000s
作为输出。它没有写在如何运行测试的文档中。
最佳答案
我相信你的测试方法需要从test
开始.更改 def getList
至 def testGetList
或 def test_get_list
.
与其他 python 测试一样(参见 https://docs.python.org/2/library/unittest.html#basic-example ),如果方法不以 test
开头它们不会作为测试运行。
关于python - 如何运行测试 django rest 框架测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29633866/