2012-03-13 51 views
0

的名稱文件我下面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目錄定義是不能夠引導測試框架找到現有的測試。

回答

1

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