Python Django django.test.Client를 이용한 유닛 테스트
조회수 1899회
장고에서 제공하는 유닛테스트용 클래스 client 를 이용하여 제가 만든 웹페이지를 테스트해보고 싶습니다.
from django.conf import settings
from django.test import Client
settings.configure()
c = Client()
response = c.get('/')
print response.status_code
response = c.post('/login/', {'user_id':'test', 'user_pw':'testing'})
print response.status_code
테스트 코드는 다음과 같이 만들었습니다.
그런데 테스트를 실행해보니 AttributeError: 'module' object has no attribute 'ROOT_URLCONF'
에러가 발생합니다.
이런경우 어떻게하면 좋을까요?
1 답변
-
from django.test import TestCase, Client class ExampleTestCase(TestCase): def setUp(self): def test_your_test(self): c = Client() response = c.get('/') print response.status_code response = c.post('/login/', {'user_id':'test', 'user_pw':'testing'}) print response.status_code
python ./manage.py test 로 실행해야지 싶습니다.
django 테스트 케이스 참고 페이지: https://docs.djangoproject.com/en/2.0/topics/testing/overview/
댓글 입력