14

I'm learning django rest framework. I wrote a simple test like this:

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)

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:

python manage.py test

i get

Ran 0 tests in 0.000s

as output. It's not written in documentation to how to run the tests.

2 Answers 2

14

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i'll, in 4 minutes. ^^
lol facepalm moment for me
0

from rest_framework.test import APITestCase

from rest_framework import status

class Portfolio_api_test(APITestCase): def setUp(self): Your code

def test_your_function_name(self):
    response = self.client.get('url')
    self.assertEqual(response.status_code, status.HTTP_200_OK)

Your test function name should start with test_your_function_name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.