2013-03-03 133 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>