PHPUnit

2018-02-24 15:42 更新

PHPUnit

<phpunit> 元素的屬性用于配置 PHPUnit 的核心功能。

<phpunit
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
         backupGlobals="true"
         backupStaticAttributes="false"
         <!--bootstrap="/path/to/bootstrap.php"-->
         cacheTokens="false"
         colors="false"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         forceCoversAnnotation="false"
         mapTestClassNameToCoveredClassName="false"
         printerClass="PHPUnit_TextUI_ResultPrinter"
         <!--printerFile="/path/to/ResultPrinter.php"-->
         processIsolation="false"
         stopOnError="false"
         stopOnFailure="false"
         stopOnIncomplete="false"
         stopOnSkipped="false"
         stopOnRisky="false"
         testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
         <!--testSuiteLoaderFile="/path/to/StandardTestSuiteLoader.php"-->
         timeoutForSmallTests="1"
         timeoutForMediumTests="10"
         timeoutForLargeTests="60"
         verbose="false">
  <!-- ... -->
</phpunit>

以上 XML 配置對(duì)應(yīng)于在the section called “命令行選項(xiàng)”描述過的 TextUI 測(cè)試執(zhí)行器的默認(rèn)行為。

其他那些不能用命令行選項(xiàng)來配置的選項(xiàng)有:

convertErrorsToExceptions
默認(rèn)情況下,PHPUnit 將會(huì)安插一個(gè)錯(cuò)誤處理函數(shù)來將以下錯(cuò)誤轉(zhuǎn)換為異常:

  • E_WARNING
  • E_NOTICE
  • E_USER_ERROR
  • E_USER_WARNING
  • E_USER_NOTICE
  • E_STRICT
  • E_RECOVERABLE_ERROR
  • E_DEPRECATED
  • E_USER_DEPRECATED

convertErrorsToExceptions 設(shè)為 false 可以禁用此功能。

convertNoticesToExceptions
此選項(xiàng)設(shè)置為 false 時(shí),由 convertErrorsToExceptions 安插的錯(cuò)誤處理函數(shù)不會(huì)將 E_NOTICEE_USER_NOTICEE_STRICT 錯(cuò)誤轉(zhuǎn)換為異常。

convertWarningsToExceptions
此選項(xiàng)設(shè)置為 false 時(shí),由 convertErrorsToExceptions 安插的錯(cuò)誤處理函數(shù)不會(huì)將 E_WARNINGE_USER_WARNING 錯(cuò)誤轉(zhuǎn)換為異常。

forceCoversAnnotation
只記錄使用了 @covers 標(biāo)注(文檔參見the section called “@covers”)的測(cè)試的代碼覆蓋率。

timeoutForLargeTests
如果實(shí)行了基于測(cè)試規(guī)模的時(shí)間限制,那么此屬性為所有標(biāo)記為 @large 的測(cè)試設(shè)定超時(shí)限制。在配置的時(shí)間限制內(nèi)未執(zhí)行完畢的測(cè)試將視為失敗。

timeoutForMediumTests
如果實(shí)行了基于測(cè)試規(guī)模的時(shí)間限制,那么此屬性為所有標(biāo)記為 @medium 的測(cè)試設(shè)定超時(shí)限制。在配置的時(shí)間限制內(nèi)未執(zhí)行完畢的測(cè)試將視為失敗。

timeoutForSmallTests
如果實(shí)行了基于測(cè)試規(guī)模的時(shí)間限制,那么此屬性為所有未標(biāo)記為 @medium@large 的測(cè)試設(shè)定超時(shí)限制。在配置的時(shí)間限制內(nèi)未執(zhí)行完畢的測(cè)試將視為失敗。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)