为什么 PHPUnit 不接受 XML 定义的测试套件?
我正在关注 ZendCast
用于在 Zend Framework 之上编写单元测试。在视频和其他一些来源之间,我的 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”都无法打开。在 C:\Program Files (x86)\php\pear\PHPUnit\Util\Skeleton\Test.php 第 102 行
这似乎表明 PHPUnit 正在寻找一个基于我命名的测试套件的文件,以便找到运行测试,而不是尊重我让它针对整个目录运行的愿望。尽管 PHPUnit 的文档非常明确地说允许以这种方式定义测试套件。
我做错了什么?
I'm following along on the ZendCast
for writing unit tests on top of the Zend Framework. Between the video and a few other sources, my phpunit.xml
looks like the following:
<?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>
Unfortunately, when I try to run PHPUnit with this file, while I can verify that the "boostrap.php" file does, run, I get this error at runtime:
PHPUnit_Framework_Exception: Neither "RefreshTests.php" nor "RefreshTests.php" could be opened. in C:\Program Files (x86)\php\pear\PHPUnit\Util\Skeleton\Test.php on line 102
This seems to indicate that PHPUnit is looking for a file based on what I named the test suite in order to find the tests to run, instead of respecting my wishes to have it run against the entire directory. This despite that PHPUnit's documentation quite explicitly says that defining a test suite this way is allowed.
What have I done incorrectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误意味着 phpunit 在递归扫描时无法在
"."
目录中找到任何测试类。如果找不到任何测试文件,它会尝试打开一个名为 testsuite 的 .php 文件。因此出现了错误。
确保您的 TestClass 以
Test.php
结尾,或将suffix=".php"
(或其他内容)添加到您的
标记中并确保该文件包含一个也以Test
结尾的类。The error means that phpunit can't find any test class within the
"."
directory while scanning it recursively.If it can't find any test files it then tries to open a .php file named like the testsuite. Hence the error.
Make sure your TestClasses end in
Test.php
or add asuffix=".php"
(or whatever) to your<directory>
tag and make sure that file contains a class that also ends inTest
.