问题描述
||
我有一个Zend Framework项目,并且想要使用单元测试来对其进行测试。
在tests文件夹中,我具有ѭ0,如下所示;
<PHPunit bootstrap=\"./application/bootstrap.PHP\" colors=\"true\">
<testsuite name=\"Application Test Suite\">
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=\".PHP\">../application/</directory>
<exclude>
<directory suffix=\".phtml\">../application/</directory>
<file>../application/Bootstrap.PHP</file>
<file>../application/controllers/ErrorController.PHP</file>
</exclude>
</whitelist>
</filter>
<logging>
<log type=\"coverage-html\" target=\"./log/reprot\" charset=\"UTP-8\"
yui=\"true\" highlight = \"true\" lowUpoerBound=\"50\" highLowerBound=\"80\"/>
<log type=\"textdox\" target=\"./log/testdox.html\" />
</logging>
我在/ tests / application文件夹中有“ 2”,如下所示:
<?PHP
error_reporting(E_ALL | E_STRICT);
// Define path to application directory
defined(\'APPLICATION_PATH\')
|| define(\'APPLICATION_PATH\',realpath(dirname(__FILE__) . \'/../../application\'));
// Define application environment
defined(\'APPLICATION_ENV\')
|| define(\'APPLICATION_ENV\',(getenv(\'APPLICATION_ENV\') ? getenv(\'APPLICATION_ENV\') : \'testing\'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEParaTOR,array(
realpath(APPLICATION_PATH . \'/../library\'),get_include_path(),)));
require_once \'Zend/Loader/Autoloader.PHP\';
require_once \'controllers/ControllerTestCase.PHP\';
Zend_Loader_Autoloader::getInstance();
当我转到命令行时,运行以下命令
PHPunit --configuration PHPunit.xml
它引发异常:
PHP致命错误:消息未捕获的异常\'PHPUnit_Framework_Exception \'
\“ Application Test Suite.PHP \”和\“ Application Test Suite.PHP \”都不是
在D:\\ PHP \\ PHP5 \\ PEAR \\ PHPUnit \\ Util \\ Skeleton \\ Test.PHP中打开。\:102
堆栈跟踪:
#0 D:\\ PHP \\ PHP5 \\ PEAR \\ PHPUnit \\ TextUI \\ Command.PHP(157):PHPUnit_Util_Skeleton_Test-
> __ construct(\'Application Tes ... \',\'\')
#1 D:\\ PHP \\ PHP5 \\ PEAR \\ PHPUnit \\ TextUI \\ Command.PHP(129):PHPUnit_TextUI_Command-> run
(数组,正确)
#2 D:\\ PHP \\ PHP5 \\ PHPunit(53):PHPUnit_TextUI_Command :: main()
#3 {main}
在第102行的D:\\ PHP \\ PHP5 \\ PEAR \\ PHPUnit \\ Util \\ Skeleton \\ Test.PHP中抛出
我该如何解决?
解决方法
您会注意到它引发了异常,因为它正在寻找与您为测试套件提供的“ 5”相同的文件。您实际上需要编写一个测试套件,然后将该测试套件的名称提供给您的配置:http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html
,我在相同的设置下遇到了同样的问题。据我了解,最新版本的PHPUnit需要至少一项实际测试才能正常运行。创建一个简单的测试后,它就可以了。
myProject / tests / application / DemoTest.php
<?php
class DemoTest extends ControllerTestCase
{
public function setUp() {
parent::setUp();
}
public function testCanDoUnitTest() {
$this->assertTrue(true);
}
}
,我注意到您未使用包含多次出现的ѭ8的ѭ7。
这是我的phpunit.xml,适用于Zend Framework项目:
<testsuites>
<testsuite name=\"UnitTests\">
<directory>./library</directory>
</testsuite>
<testsuite name=\"ApplicationTests\">
<directory>./application</directory>
</testsuite>
</testsuites>