PHPUnit Eclipse 配置: No Tests Found

标签 php eclipse phpunit xdebug

在尝试将 Eclipse 与 PHPUnit 设置为单元测试库时,我在尝试运行一个简单的测试用例时遇到了困难。作为引用,我关注了this使用 PHPUnit/Xdebug/Makegood 设置 Eclipse 的教程,与给出的指南的唯一偏差是为 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>

现在,问题的根源在于我似乎无法使用 Makegood 从 Eclipse 运行 PHPUnit 测试。我编写的唯一测试(位于“/path/to/application/tests/”文件夹中,名为“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));
    }
}
?>

为了运行测试,我右键单击“tests”文件夹,然后在 Eclipse 中单击“运行所有测试”,这将打印到控制台:

PHPUnit 3.7.15 by Sebastian Bergmann.

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

Time: 0 seconds, Memory: 5.00Mb

No tests executed!

现在,当我尝试使用“path/to/application/tests/”目录中的命令“phpunit test.php”从命令行运行这些测试时,我得到以下控制台输出:

PHPUnit 3.7.15 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 3.25Mb

OK (1 test, 5 assertions)

很明显,我没有正确告诉 Makegood 在哪里可以找到测试文件/如何运行测试,但我似乎无法确定如何解决这个问题。毫无疑问,对于所有 PHPUnit 组件如何在 Eclipse 中组合在一起,我的心理模型很糟糕,因此任何有助于我理解该架构的帮助都将不胜感激。提前致谢!

最佳答案

“运行所有测试”无法按照您尝试使用的方式工作。 “运行所有测试”运行您选择作为“测试文件夹”之一的测试(见下文)

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>

关于PHPUnit Eclipse 配置: No Tests Found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15188848/

相关文章:

php - Codeception:从数据库中清理测试数据

php - 如何使用格式为 [col1=>[col2=>col3,col2=>col3]] 的 PDO 获取数据?

visual-studio - #eclipse的地区模拟

java - 不幸的是 <app><package> 已在 android 模拟器中停止-错误,如何解决这个问题?

phpunit & paratest & Laravel - 创建测试存储目录时随机失败

php - 如何通过更改通过引用传递的参数来对调用具有副作用的函数的方法进行单元测试?

phpunit - 如果调试客户端未在监听,则 xdebug.start_start_with_request=yes WITHOUT 错误

php - 应用程序如何可能对已删除且不存在的函数抛出重新声明错误?

php - php 中的母版页

eclipse - web.xml中添加servlet导致tomcat无法启动