【发布时间】:2013-03-20 03:32:35
【问题描述】:
我尝试使用 Zend_Test_PHPUnit 为我的应用程序编写单元测试,但我总是得到 p>
1) IndexControllerTest::testValidation
Failed asserting last controller used <"error"> was "test"
我已经创建了一个测试控制器,但即使在那里我也无法让它工作。
谁能帮忙?
谢谢!
class TestController extends Zend_Controller_Action
{
public function indexAction()
{
print 'test';
}
}
引导是:
// 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'; Zend_Loader_Autoloader::getInstance();
phpunit.xml 是:
<phpunit bootstrap="./bootstrap.php">
<testsuite name="Application Test Suite">
<directory>./application</directory>
</testsuite>
<testsuite name="Library Test Suite">
<directory>./library</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../library/</directory>
<directory suffix=".php">../application/</directory>
</whitelist>
</filter>
</phpunit>
测试控制器是
class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
$this->bootstrap = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
parent::setUp();
}
public function testValidation()
{
$this->dispatch('/test/');
$this->assertController("test");
}
}
【问题讨论】:
标签: php zend-framework