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 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序