環境:ubuntu10.10
百度來的例子大多是這樣的
<?php //test.php 編寫了測試案例的PHP檔案 require_once('TestCase.php'); class OpenTestCase extends PHPUnit_Framework_TestCase { public function testRegister() { //... } }?>
可以通過這樣來執行自動化測試
$ phpunit test.php
報錯,提示找不到 PHPUnit_Framework_TestCase 和 TestCase.php
通過尋找資料,得到如下解決方案:
1) 先找到php.ini檔案 這個檔案在 /etc/php5/apache2/php.ini
2) 查看php.ini的include_path參數,這個參數指定了php模組安裝目錄,這個目錄是/usr/share/php
3) 進入該目錄發現PHPUnit目錄,我們要的TestCase.php在這個PHPUnit/Framework下 (/usr/share/php/PHPUnit/Framework/TestCase.php)
4) 我們的代碼其實應該從/usr/share/php以相對路徑往下引用
<?php //test.php 編寫了測試案例的PHP檔案 require_once('PHPUnit/Framework/TestCase.php'); class OpenTestCase extends PHPUnit_Framework_TestCase { public function testRegister() { //... } }?>
參考資料
http://kibamaple.iteye.com/blog/1260386
http://www.ltesting.net/ceshi/open/kydycsgj/phpunit/
http://blog.163.com/zzdjk6@126/blog/static/172681462201242631221548/
http://hi.baidu.com/hulongbing/item/7d8aa2d41b2dce2a39f6f784