ก่อนทำตามบทความนี้ ต้องอ่านวิธีติดตั้ง Unittest และ Selenium ที่
เตรียมเครื่องทำ สำหรับ PHPUnit และ Selenium
หลังจากที่เรา ใช้ yiic webapp
สร้าง webapplication จะได้ โครงสร้างไฟล์ และ ไดเรกทอรี สำหรับ test ระบบตามโครงสร้างดังนี้
protected/ protected application files
tests/ tests for the application
fixtures/ ข้อมูลสำหรับ test เก็บในฐานข้อมูล
functional/ เก็บ functional tests
unit/ ไฟล์สำหรับทำ unit tests
report/ เก็บไฟล์ coverage reports
bootstrap.php ไฟล์สำหรับกำหนดค่าต่างๆ ไว้ใช้งานเมื่อเริ่มรันโปรแกรม
phpunit.xml PHPUnit configuration file ของ PHPUnit
WebTestCase.php the base class for Web-based functional tests
วิธีรันโปรแกรมสำหรับ test (
Testing การทดสอบ โปรแกรมประยุกต์บนเว็บ
unit tests และ functional tests) สามารถรันโดยใช้คำสั่ง
% cd testdrive/protected/tests
% phpunit functional/PostTest.php // executes an individual test
% phpunit --verbose functional // executes all tests under 'functional'
% phpunit --coverage-html ./report unit
ถ้าต้องการรัน coverage reports ต้องติดตั้ง xdebug extension ไว้ในเครื่องด้วย (XAMPP มีมาให้เราใช้อยู่แล้ว แค่เปิดใช้งานมัน)