dongli7236
2013-03-03 18:02 阅读 198
已采纳

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 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>
    
    点赞 8 评论 复制链接分享

相关推荐