why does PHPUnit try to find a file with the name of the testsuite?(为什么 PHPUnit 会尝试查找具有测试套件名称的文件?)
问题描述
我的 phpunit.xml 文件中有这个:
I have this in my phpunit.xml file:
<phpunit ...>
<testsuites>
<testsuite name="MyTests">
<directory>../path/to/some/tests</directory>
</testsuite>
</testsuites>
... // more settings for <filter> and <logging>
</phpunit>
当我去运行它时,我得到了这个错误:
And when I go to run it, I get this error:
PHP fatal error: Uncaught exception 'PHPUnit_Framework_Exception'
with message 'Neither "MyTests.php" nor "MyTests.php" could be opened.'
为什么 PHPUnit 会给我这个错误,如果我给它一个目录来查找测试,为什么它会寻找MyTests.php"?
Why does PHPUnit give me this error, and why is it looking for "MyTests.php" if I gave it a directory in which to look for tests?
在相关说明中,当我在其他测试中添加更多 <testsuite>
条目时,PHPUnit 运行时不会出错.这是怎么回事?
And on a related note, when I add more <testsuite>
entries with other tests, PHPUnit runs without error. What's up with that?
推荐答案
默认情况下,PHPUnit 会添加在 *Test.php
文件中找到的所有 *Test
类"(参见 PHPUnit 文档).如果它没有找到与该描述匹配的任何文件(例如,定义 SomeTest
类的 SomeTest.php
文件),它会回退到基于测试套件的名称属性.
By default PHPUnit will add "all *Test
classes that are found in *Test.php
files" (see PHPUnit docs). If it doesn't find any files matching that description, (e.g. a SomeTest.php
file defining a SomeTest
class), it falls back to looking for a file based on the name attribute of the test suite.
解决方案是创建一个与该描述匹配的文件,以便 PHPUnit 不会退回到其默认的按测试套件名称搜索:
The solution is to create a file matching that description so that PHPUnit doesn't fall back to its default of searching by the testsuite name:
<?php
// in ../path/to/some/tests/SomeTest.php:
class SomeTest extends PHPUnit_Framework_TestCase {
public function test() {
//... test cases here
}
}
?>
现在你应该可以运行 phpunit
没有错误了:
Now you should be able to run phpunit
without errors:
$ phpunit
PHPUnit 3.5.14 by Sebastian Bergmann.
.
Time: 0 seconds, Memory: 10.75Mb
OK (1 test, 0 assertions)
如果 PHPUnit 能够找到匹配的测试用例以在其他套件下运行,则添加更多 testsuite
条目时它将正常工作.如果它找到要在任何测试套件中运行的测试,它不会通过 name
属性搜索它找不到任何东西的套件.
It will work without errors when you add more testsuite
entries if PHPUnit is able to find matching test cases to run under those other suites. If it finds tests to run in any testsuite, it won't resort to searching by the name
attribute for the suites it couldn't find anything for.
这篇关于为什么 PHPUnit 会尝试查找具有测试套件名称的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 PHPUnit 会尝试查找具有测试套件名称的文件?
基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01