PHPUnit的引发异常时,不会找到测试套件

PHPUnit的引发异常时,不会找到测试套件

问题描述:

的名称文件我下面Jon´s screencast about Unit Testing with PhpUnit and ZF当我在这个question ratzip描述的完全相同的错误。PHPUnit的引发异常时,不会找到测试套件

正如他评论的那样,即使在创建测试后,我也有同样的问题,建议here:出于某种原因,有一些脚本寻找一个名为我命名我的测试套件(MyApp.php或其他什么)的文件... )。

我环顾四周,但wasn't能找到我应该创建这个文件,包含必要内容。

但是,在某时某刻,后读了这question about how to run a specific phpunit xml testsuite,我决定尝试明确地插入文件中的测试套件部分。

我phpunit.xml现在是:

<phpunit bootstrap="./application/bootstrap.php" colors="true"> 
<testsuites> 
    <testsuite name="MyApp"> 
     <file>./application/(path_to_model_inside_module)/ModelTests.php</file> 
     <directory>./</directory>  
    </testsuite> 
</testsuites> 

<filter> 

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

</filter> 

即使它似乎有点绝望,这个错误不是发生了现在的测试工作。

,但我感觉unconfortable它,因为我无法理解之前,为什么这种明晰的“固定”它的文件是什么问题。

我想不通为什么XML目录定义是不能够引导测试框架找到现有的测试。

PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "$TEST_SUITE_NAME.php" nor "$TEST_SUITE_NAME.php" could be opened.' in ...

这是PHPUnits 非常

He buddy! Small issue over here: I was trying to find some tests to execute but I didn't find any so I tried to load a file named like the test suite and not even that exists. I can't execute any tests.. can you help me out here? :(

总之跟它神秘的方式:

在XML扫描的东西后,我没有找到任何测试!

为什么你的情况发生呢?

的PHPUnit会在test.php的结尾的文件,但在TestS.php文件结束。额外的“S”意味着PHPUnit在扫描目录时不会拾取文件。这也是为什么添加文件标签有帮助的原因。

重命名它做ModelTest.php,你可以摆脱文件标签:)

,或者如果你想让你的文件名告诉PHPUnit的有关命名架构使用:

<directory suffix="Tests.php">./</directory> 
+0

TXS @edorian ,指向额外的'S'...这可能是我的问题的一部分... 我也发现了一些其他技巧在答案很相似的问题在http://stackoverflow.com/questions/7045834/ why-does-phpunit-try-to-find-a-file-name-of-the-testsuite 创建了一个“/tests/TheSuiteNameTest.php”,将该套件命名为TheSuiteName,并将th e错误消失了...... – 2012-03-15 00:42:25

+0

@RodrigoAoCubo你应该**不需要**“TestSuiteName.php”或类似的东西了。这在当天被用于编排测试套件,但已被xml配置取代。 – edorian 2012-03-15 08:42:49

+0

你说得对,我已经删除了“TestSuitName”。php“文件,它现在仍然可以工作,我没有那个尾随的's'。 – 2012-03-16 01:29:50