【问题标题】:Why will PHPUnit not accept an XML defined test suite?为什么 PHPUnit 不接受 XML 定义的测试套件?
【发布时间】:2011-11-10 06:44:54
【问题描述】:

我正在关注ZendCast 在 Zend 框架之上编写单元测试。在视频和其他一些来源之间,我的phpunit.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./application/bootstrap.php" colors="true">

    <testsuites>
        <testsuite name="RefreshTests">
            <directory>./</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory suffix=".php">../application</directory>
        </whitelist>
        <exclude></exclude>
    </filter>

    <logging>
        <log type="coverage-html" target="./log/report" charset="UTF-8"
        yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" />
        <log type="testdox" target="./log/testdox.html" />
    </logging>

</phpunit>

不幸的是,当我尝试使用此文件运行 PHPUnit 时,虽然我可以验证“boostrap.php”文件是否确实运行,但我在运行时收到此错误:

PHPUnit_Framework_Exception:“RefreshTests.php”和“RefreshTests.php”都无法打开。在第 102 行的 C:\Program Files (x86)\php\pear\PHPUnit\Util\Skeleton\Test.php 中

这似乎表明 PHPUnit 正在寻找基于我命名的测试套件的文件,以便找到要运行的测试,而不是尊重我的愿望让它针对整个目录运行。尽管如此PHPUnit's documentation quite explicitly says that defining a test suite this way is allowed.

我做错了什么?

【问题讨论】:

  • 可能是 Windows 问题。你用的是什么版本的phpunit?梨分布也可能过时
  • 错误看起来测试的路径不正确,或者没有可用的测试(你有带前缀测试的文件吗?例如 ClassTest.php?)
  • 是的,你能把文件放到github上吗?
  • @Tim:不幸的是,不,我不能。呸!当一个人在自己的东西上工作时,这很容易问:P

标签: php zend-framework phpunit


【解决方案1】:

该错误表示phpunit在递归扫描时无法在"."目录中找到任何测试类。

如果找不到任何测试文件,它会尝试打开一个名为 testsuite 的 .php 文件。因此出现错误。

确保您的 TestClasses 以 Test.php 结尾或在您的 &lt;directory&gt; 标记中添加 suffix=".php"(或其他),并确保该文件包含一个也以 Test 结尾的类。

【讨论】:

    猜你喜欢
    • 2011-07-27
    • 2011-04-09
    • 2012-05-16
    • 2019-10-22
    • 2011-12-28
    • 2016-05-24
    • 2011-10-26
    • 1970-01-01
    • 2015-03-15
    相关资源
    最近更新 更多