- Detail Commit:
$ mkdir functional_tests
$ touch functional_tests/__init__.py
จากนั้นเราจะย้าย functional test ของเราจากไฟล์แบบ standalone (functional_tests.py) ไปเป็น test.py ในโฟรเดอร์ functional_tests ซึ่งเราใช้ git mv เพื่อให้ Git รู้ว่าเราได้ย้ายไฟล์:
$ git mv functional_tests.py functional_tests/tests.py
$ git status # shows the rename to functional_tests/tests.py and __init__.py
จากนั้นเข้าไปใน functional_tests.py แล้วลบ unittest.TestCase ที่อยู่ใน class NewVisitorTest ออกจากนั้นใส่ LiveServerTestCase ไปใน class NewVisitorTest และเปลี่ยนจาก
self.browser.get('http://localhost:8000/fooddetail')เป็น
self.browser.get(self.live_server_url)สาเหตุที่เราต้องเปลี่ยนเพราะ LiveServerTestCase สร้าง test database โดยอัตโนมัติ
(เช่นเดียวกับใน unit test)
- File: functional_tests.py
- File: functional_tests/tests.py
- File: fooddetail/templates/fooddetail/index.html
จากนั้นมาทำ unit test โดยเรา test แค่ การ return template และการแสดงชื่ออาหารบนหน้าเว็บ
- fooddetail/tests.py
No comments:
Post a Comment