基於PHPUnit編寫測試案例

來源:互聯網
上載者:User

環境: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.