我有一个Zend Framework项目,并希望使用单元测试来测试它.
<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文件夹中有bootstrap.PHP,如下所示:
<?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 Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "Application Test Suite.PHP" nor "Application Test Suite.PHP" could be opened.' in D:\PHP\PHP5\PEAR\PHPUnit\Util\Skeleton\Test.PHP:102 Stack trace: #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 (Array,true) #2 D:\PHP\PHP5\PHPunit(53): PHPUnit_TextUI_Command::main() #3 {main} thrown in D:\PHP\PHP5\PEAR\PHPUnit\Util\Skeleton\Test.PHP on line 102
我该怎么办呢?
您会注意到它抛出异常,因为它查找的文件名与您为测试套件提供的名称相同.您需要实际编写测试套件,然后将该测试套件的名称提供给您的配置:
http://www.phpunit.de/manual/3.2/en/organizing-test-suites.html