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 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示