2013-03-03 131 views
2

在嘗試使用PHPUnit作爲單元測試庫設置Eclipse時,我自己試圖運行一個簡單的測試用例。作爲參考,我也跟着this教程設置Eclipse使用PHPUnit/Xdebug的/明鉅,從給定的被設置爲PHPUnit的下面的配置文件/明鉅準則的唯一偏差:PHPUnit Eclipse配置:未發現測試

config.xml: 
    <phpunit backupGlobals="true" 
     backupStaticAttributes="false" 
     cacheTokens="false" 
     colors="false" 
     convertErrorsToExceptions="true" 
     convertNoticesToExceptions="true" 
     convertWarningsToExceptions="true" 
     forceCoversAnnotation="false" 
     mapTestClassNameToCoveredClassName="false" 
     printerClass="PHPUnit_TextUI_ResultPrinter" 
     processIsolation="false" 
     stopOnError="false" 
     stopOnFailure="false" 
     stopOnIncomplete="false" 
     stopOnSkipped="false" 
     testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" 
     strict="false" 
     verbose="false"> 
    <testsuites> 
     <testsuite name="My Test Suite"> 
      <directory suffix=".php">/path/to/application/tests/</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 

現在的根問題在於,我似乎無法使用Makegood從Eclipse運行PHPUnit測試。我寫的唯一的測試(位於「/路徑/到/應用/測試/」的名義下「test.php的」文件夾)看起來如下(從PHPUnit Manual直接服用):

<?php 
class StackTest extends PHPUnit_Framework_TestCase 
{ 
    public function testPushAndPop() 
    { 
     $stack = array(); 
     $this->assertEquals(0, count($stack)); 

     array_push($stack, 'foo'); 
     $this->assertEquals('foo', $stack[count($stack)-1]); 
     $this->assertEquals(1, count($stack)); 

     $this->assertEquals('foo', array_pop($stack)); 
     $this->assertEquals(0, count($stack)); 
    } 
} 
?> 
塞巴斯蒂安伯格曼

PHPUnit的3.7.15:

爲了運行測試,我對「測試」文件夾,右鍵單擊,打在Eclipse「運行所有測試」,它打印到控制檯。

配置從 /path/to/application/config.xml讀

時間:0秒,內存:5.00Mb

沒有測試執行!

現在,當我試圖用命令「PHPUnit的test.php的」,在運行命令行這些測試「路徑/到/應用/測試/」目錄下,我得到以下控制檯輸出:

PHPUnit 3.7.15 by Sebastian Bergmann。

時間:0秒,內存:3.25MB

OK(1次測試,5個斷言)

很明顯,我無法正常告訴明鉅在哪裏可以找到測試文件/如何運行測試,但我似乎無法確定如何解決這個問題。對於所有PHPUnit組件如何在Eclipse中進行合併,我無疑有一個錯誤的心理模型,因此任何幫助我幫助理解架構的方法都將不勝感激。提前致謝!

回答

2

'運行所有測試'不會像您嘗試使用它的方式工作。 「運行所有測試」運行已選定爲您的「測試文件夾」的其中一個不斷測試(見下文)

enter image description here

我居然改變了我的測試文件夾,這個

enter image description here

它只在RuleData文件夾中運行測試。你可以點擊你喜歡的任何地方,'運行所有測試'將以這種方式表現。如果只想運行文件夾中的測試,只需選擇'運行測試'

另外這裏是我的phpunit xml配置,它位於測試目錄中。

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit 
     backupStaticAttributes="false" 
     backupGlobals="false" 
     bootstrap="./../application/third_party/CIUnit/bootstrap_phpunit.php" 
     cacheTokens="false" 
     colors="false" 
     convertErrorsToExceptions="true" 
     convertNoticesToExceptions="true" 
     convertWarningsToExceptions="true" 
     forceCoversAnnotation="false" 
     mapTestClassNameToCoveredClassName="false" 
     printerClass="PHPUnit_TextUI_ResultPrinter" 

     processIsolation="false" 
     stopOnError="false" 
     stopOnFailure="false" 
     stopOnIncomplete="false" 
     stopOnSkipped="false" 
     testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader" 

     strict="false" 
     verbose="true" 

     > 
    <php> 
     <ini name="memory_limit" value="2047M" /> 
    </php> 

    <testsuites> 
     <testsuite name="AllTests"> 
      <directory>.</directory> 
     </testsuite> 
    </testsuites> 

    <filter> 
     <blacklist> 
     <directory suffix=".php">./../../</directory> 
     <file></file> 
     <exclude> 
      <file></file> 
     </exclude> 
     </blacklist> 
     <whitelist processUncoveredFilesFromWhitelist="true"> 
      <directory suffix=".php">./../application/models</directory> 
      <directory suffix=".php">./../application/controllers</directory> 
      <directory suffix=".php">./../application/libraries</directory> 
      <directory suffix=".php">./../application/helpers</directory> 
     <file></file> 
     <exclude> 
      <directory suffix="index.php">./../application</directory> 
      <file></file> 
     </exclude> 
     </whitelist> 
    </filter> 
</phpunit>