我試圖用Zend_Test_PHPUnit編寫單元測試我的應用程序,但我總是隻得到Zend框架單元測試
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 /裝載機/ 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");
}
}
這是缺少的觀點。我只創建了一個JSON-API,這就是爲什麼我不需要視圖。 謝謝! – thesonix 2012-01-05 10:55:47