UnitTest๋, ํ
์คํธ ํ ์ ์๋ ๊ฐ์ฅ ์์ ๋จ์๋ฅผ ํ
์คํธ ํ๋ ์ฝ๋๋ฅผ
์์ฑํ์ฌ ํ
์คํธํ๋ ๊ฒ์ ๋งํ๋ค. ํ์ด์ฌ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค ํ๋๋ก ์์ฃผ ์ ์ฉํ ํ
์คํธ ๋ชจ๋์ด๋ค.
์ฌ๊ธฐ์ ๋งํ๋ ๊ฐ์ฅ ์์ ๋จ์๋ ํจ์์ ๋ฉ์๋๊ฐ ์๋ค.
TestCate
-UnitTest framework
์ ํ ์คํธ ์กฐ์ง์ ๊ธฐ๋ณธ ๋จ์
Fixture
- ํ ์คํธ ์งํ์ ํ์ํ ํ ์คํธ์ฉ ๋ฐ์ดํฐ ํน์ ์ค์ , ์ฃผ๋ก ํ ์คํธ๊ฐ ์คํ ๋๊ธฐ ์ ์ด๋ ํ์ ์๊ธด๋ค.
Assertion
-UnitTest
์์ ํ ์คํธ๊ฐ ์ ๋๋ก ๋๋์ง ํ์ธ
class UserSignUp(TestCase):
def setUp(self):
User.objects.create(
email = 'inah@unit.test',
password = '^-^test1234'
)
def tearDown(self):
User.objects.all().delete()
def test_signup_success(self_:
client = Client()
user = {
'email' : 'rara@unit.test',
'password' : 'rarara^^777'
}
response = client.post('user/signup', json.dumps(user), content_type='application/json')
self.assertEqual(response.status_code, 201)
1. database์ ์ด๋ฏธ ์๋ email์ผ ๋
def test_signup_email_exists(self):
client = Client()
user = {
'email' : 'rara@unit.test',
'password' : 'rarara^^777'
}
response = client.post('user/signup', json.dumps(user), content_type='application/json')
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json(), {'message' : 'ALREADY_EXISTS_EMAIl'})