dongli7236 2013-03-03 18:02
浏览 227
已采纳

PHPUnit Eclipse配置:未找到测试

In attempting to set up Eclipse with PHPUnit as a unit testing library, I've gotten myself stuck attempting to run a simple test case. For reference, I followed this tutorial to set up Eclipse with PHPUnit/Xdebug/Makegood, the only deviation from the guidelines given was setting up the following configuration file for PHPUnit/Makegood:

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>

Now, the root of the problem lies in the fact that I can't seem to run PHPUnit tests from Eclipse with Makegood. The only test I've written (located in the "/path/to/application/tests/" folder under the name "test.php") looks like the following (taken directly from the 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));
    }
}
?>

In order to run the tests, I right-click on the "tests" folder and hit "Run All Tests" in Eclipse, which prints to the console:

PHPUnit 3.7.15 by Sebastian Bergmann.

Configuration read from /path/to/application/config.xml

Time: 0 seconds, Memory: 5.00Mb

No tests executed!

Now, when I attempt to run these tests from the command line with the command "phpunit test.php" in the "path/to/application/tests/" directory, I get the following console output:

PHPUnit 3.7.15 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 3.25Mb

OK (1 test, 5 assertions)

It's evident that I'm not correctly telling Makegood where to find the test files/how to run the tests, but I can't seem to identify how to fix this. I undoubtedly have a bad mental model for how all the PHPUnit components are fitting together within Eclipse, so any help in the way of aiding my understanding of the architecture would be greatly appreciated. Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongliang1873 2013-03-13 06:58
    关注

    'Run All Tests' doesn't work the way you're trying to use it. 'Run all tests' runs which ever tests you have selected as one of your 'Test Folders' (see below)

    enter image description here

    I actually changed my tests folder to this

    enter image description here

    And it only ran the tests in the RuleData folder. You can click anywhere you like and 'Run All Tests' will behave this way. If you want to run only the tests in a folder just select 'Run Tests'

    Also Here's my phpunit xml config which is in the tests directory.

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?