I’m learning django rest framework. I wrote a simple test like this:
JavaScript
x
10
10
1
from rest_framework import status
2
from rest_framework.test import APITestCase
3
4
5
class ClinicTestCase(APITestCase):
6
def getList(self):
7
factory = APIRequestFactory()
8
request = factory.get('/Clinic/')
9
self.assertEqual(response.status_code, status.OK)
10
my api returns empty json array for that request. What i don’t know is, how do i run this test?
when i use this command:
JavaScript
1
2
1
python manage.py test
2
i get
JavaScript
1
2
1
Ran 0 tests in 0.000s
2
as output. It’s not written in documentation to how to run the tests.
Advertisement
Answer
I believe your test methods need to start with test
. Change def getList
to def testGetList
or def test_get_list
.
As with other python tests (see https://docs.python.org/2/library/unittest.html#basic-example), if methods do not start with test
they will not be run as tests.