phpunit.xml 用法

<phpunit bootstrap="./booten.php">

    <testsuite name="actionsuitetest">
      <directory suffix=".php">action</directory>

      <file>HuiyuanZhanghuOrder.php</file>

     <exclude>/action/HuiyuanJifenTest.php</exclude>

    </testsuite>
    
    <testsuite name="modelsuitetest">
      <directory suffix=".php">model</directory>
    </testsuite>
    
    <testsuite name="htmlsuitetest">
      <directory suffix=".php">html</directory>
    </testsuite>

    <!-- 代碼覆蓋率 -->
    <!-- 覆蓋率的測試文件,blacklist 黑名單(不需要統計覆蓋率的文件),whitelist 白名單(統計覆蓋率的測試文件) 當黑名單與白名單文件重複時,白名單起作用 
    
    -->
    <filter>
<blacklist>
    <directory suffix=".php">action</directory>
    <file>ArrayTest.php</file>
  </blacklist>
 
  <whitelist addUncoveredFilesFromWhitelist="true">
   <directory suffix=".php">action</directory>
   <directory suffix=".php">model</directory>
   <directory suffix=".php">html</directory>
   <file>ArrayTest.php</file>
   <exclude>
   <directory suffix=".php">action/lib</directory>
   <directory suffix=".php">model</directory>
   <file>action/lib/Loginxxx.php</file>
   </exclude>
  </whitelist>
</filter>
    
    <!--代碼覆蓋率報告,可以生成很多類型報告,有html(coverage-html),xml(coverage-clover),txt ,json 等等  
    <log type="coverage-php" target="/tmp/coverage.serialized"/>
  <log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
  <log type="json" target="/tmp/logfile.json"/>
  <log type="tap" target="/tmp/logfile.tap"/>
  <log type="junit" target="/tmp/logfile.xml" logIncompleteSkipped="false"/>
  <log type="testdox-html" target="/tmp/testdox.html"/>
  <log type="testdox-text" target="/tmp/testdox.txt"/>
    
    -->
    
        <logging>
         <!-- target(report/html) 生成html 文件的目錄-->
  <log type="coverage-html" target="report/html" charset="UTF-8" yui="true" highlight="false" lowUpperBound="35" highLowerBound="70"/>
  <!-- target(report/coverage/coverage.xml) 生成xml的文件名-->
  <log type="coverage-clover" target="report/coverage/coverage.xml"/>
</logging>
    <!-- 代碼覆蓋率 -->



    <php>
 <includePath>.</includePath>
 <ini name="foo" value="bar"/>
 <const name="foo" value="bar"/>
 <var name="foo" value="bar"/>
 <env name="foo" value="bar"/>
 <post name="foo" value="bar"/>
 <get name="foo" value="bar"/>
 <cookie name="foo" value="bar"/>
 <server name="foo" value="bar"/>
 <files name="foo" value="bar"/>
 <request name="foo" value="bar"/>
</php>  

</phpunit>


xml 解釋

bootstrap="./booten.php"

在測試之前加載的的PHP 文件,一般可以做一個初始化工作


<testsuite name="actionsuitetest">
      <directory suffix=".php">action</directory>
      <file>HuiyuanZhanghuOrder.php</file>
</testsuite>

測試套件,如果想測試頁面,action,model 可以多加幾個測試套件

name: 套件名稱

directory :套件測試的目錄,目錄下一般放測試文件的用例

       suffix :測試文件後綴,如果不填寫,則默認後綴爲*Test.php,即phpunit 默認會執行*Test.php  的文件

       action:測試目錄名

file:可以單獨設置測試文件

exclude:排除不需要測試的文件



 <php>
  <includePath>.</includePath>
  <ini name="foo" value="bar"/>
  <const name="foo" value="bar"/>
  <var name="foo" value="bar"/>
  <env name="foo" value="bar"/>
  <post name="foo" value="bar"/>
  <get name="foo" value="bar"/>
  <cookie name="foo" value="bar"/>
  <server name="foo" value="bar"/>
  <files name="foo" value="bar"/>
  <request name="foo" value="bar"/>
</php>  

這段xml 可以對應以下PHP 代碼

includePath

ini_set('foo', 'bar');
define('foo', 'bar');
$GLOBALS['foo'] = 'bar';
$_ENV['foo'] = 'bar';
$_POST['foo'] = 'bar';
$_GET['foo'] = 'bar';
$_COOKIE['foo'] = 'bar';
$_SERVER['foo'] = 'bar';
$_FILES['foo'] = 'bar';
$_REQUEST['foo'] = 'bar';


phpunit.xml 應用網址http://www.phpunit.de/manual/3.6/en/appendixes.configuration.html#appendixes.configuration.blacklist-whitelist

發佈了63 篇原創文章 · 獲贊 8 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章