What Are We Doing with All These Tests?
Using Selenium to Test User Interactions
-ทำการ Run server และ Run functional_tests.py
-แก้ code ที่ไฟล์ functional_tests.py-ทดสอบรันโดยคำสั่ง python3 functional_tests.py
จะทำการเปิด web browser ขึ้นมา และปิดลงไป
เนื่องจากมีการ functional_tests มีเปลี่ยนแปลงจึงทำการ commit
-git commit -am "Functional test now checks we can input a to-do item"
The “Don’t Test Constants” Rule, and Templates to the Rescue (อย่า test โดยใช้ค่าคงที่)
Refactoring to Use a Template
แก้ไข code ที่ผ่านมา โดยการใช้ Template คือ แยก ส่วนที่เป็น html กับ Method ต่างๆ ที่สำคัญอย่าแก้ code โดยไม่มีตัว test
-สร้างไฟล์
lists/templates/home.html และเขียน code
-แก้ไขไฟล์ views.py
แต่การทำงานจะยังไม่สมบูรณ์เพราะว่าการใช้ template ใน django นั้นจะมีการหาไฟล์จาก directory ที่กำหนดไว้เองแต่ในที่นี้ในไฟล์ setting ของเรายังไม่ได้เพิ่ง directory /lists/ ซึ่งเป็นส่วนของ App ที่เราเขียนขึ้นมาใหม่ลงไปดังนั้นเราจึงต้องไปแก้ไขไฟล์ settings.py ดังนี้
โดย default จะมี directory ต่างๆถูกกำหนดไว้เราแค่ต้องไปเพิ่มในส่วนของ lists ซึ่งเป็น app ที่เราเขียนขึ้นลงไป
-แก้ไขไฟล์ lists/tests.py. เพื่อทำการ unit test
ทดลอง Run functional_test.py
ทำการ commit
git commit -m "Refactor home page view to use a template"
หลักการทำงานของ
อ้างอิง http://chimera.labs.oreilly.com/books/1234000000754/ch04.html




ไม่มีความคิดเห็น:
แสดงความคิดเห็น