2012-04-23 157 views
13

我正在學習單元測試Zend Framework應用程序的繩索。到目前爲止,我已經設置了PHPUnitZend Framework一起工作,並開始編寫一些簡單的測試用例。PHPUnit代碼覆蓋率

我的問題是,我想知道爲什麼Code Coverage無法在我的phpunit.xml中的日誌記錄標記中設置。

我沒有收到任何錯誤,但沒有生成覆蓋報告。

但是它的工作原理,當我運行phpunit --coverage <dir>

我的PHPUnit的記錄部分是如下:

<phpunit bootstrap="./application/bootstrap.php" colors="true"> 
     <testsuite name="CI Test Suite"> 
      <directory>./</directory> 
     </testsuite> 
     <testsuite name="Library Test Suite"> 
      <directory>./library</directory> 
     </testsuite> 

     <filter> 
      <whitelist> 
       <directory suffix=".php">../application/</directory> 
       <exclude> 
        <directory suffix=".phtml">../application</directory> 
        <file>../application/Bootstrap.php</file> 
        <file>../application/controllers/ErrorController.php</file> 
       </exclude> 
      </whitelist> 
      <logging> 
       <log type="coverage-html" target="./log/report" charset="UTF-8" yui="true" 
    highlight="true" lowUpperBound="50" highLowerBound="80" /> 
       <log type="testdox" target="./log/testdox.html" />  
      </logging> 
     </filter> 
    </phpunit> 

之前任何人都遇到這個?那麼可能的問題是什麼?

+3

我沒有將我的日誌記錄嵌套在過濾器中......可能會有點區別 – 2012-04-23 16:43:56

回答

23

這是我的一個項目的phpunit.xml,這工作正常。正如您所看到的,日誌記錄部分位於過濾器部分之外,所以這可能是您的問題,由Mark Ba​​ker評論。我從一個小項目中選擇了這個,非常簡單。

<phpunit bootstrap="./bootstrap.php" colors="false"> 
    <testsuite name="HSSTests"> 
     <directory>./</directory> 
    </testsuite> 

    <filter> 
     <whitelist> 
      <directory suffix=".php">d:/wamp/app_hss/</directory> 
      <exclude> 
       <directory suffix=".phtml">d:/wamp/app_hss/</directory> 
       <directory suffix=".php">d:/wamp/app_hss/tests/</directory> 
      </exclude> 
     </whitelist> 
    </filter> 

    <logging> 
     <log type="coverage-html" target="./log/codeCoverage" charset="UTF-8" 
      yui="true" highlight="true" 
      lowUpperBound="50" highLowerBound="80"/> 
     <log type="testdox-html" target="./log/testdox.html" /> 
    </logging> 
</phpunit> 

您可能需要的所有信息都在PHPunit manual

+0

你是絕對正確的!日誌記錄部分不應該在過濾器部分內。 – stevepop 2012-04-24 08:14:27