为什么PHPUnit尝试查找具有测试套件名称的文件? [英] why does PHPUnit try to find a file with the name of the testsuite?

查看:73
本文介绍了为什么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类"(请参见

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尝试查找具有测试套件名称的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆