【发布时间】:2011-08-18 17:47:23
【问题描述】:
我正在尝试创建我的第一个单元测试。我使用 Zend Studio,并通过以下方式将 phpUnit 库添加到我的项目中:
Project -> Properties -> Add Library
当我将它作为 PHP 单元测试运行时,我收到以下错误:
Unable to run a PHPUnit session. Only PHPUNIT classes can be run as PHPUnit tests. Reason: Not tests found in IndexControllerTest.php
IndexControllerTest.php:
<?php
require_once 'application\controllers\IndexController.php';
require_once 'PHPUnit\Framework\TestCase.php';
/**
* IndexController test case.
*/
class IndexControllerTest extends PHPUnit_Framework_TestCase
{
/**
* @var IndexController
*/
private $IndexController;
/**
* Prepares the environment before running a test.
*/
protected function setUp ()
{
parent::setUp();
// TODO Auto-generated IndexControllerTest::setUp()
$this->IndexController = new IndexController(/* parameters */);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown ()
{
// TODO Auto-generated IndexControllerTest::tearDown()
$this->IndexController = null;
parent::tearDown();
}
/**
* Constructs the test case.
*/
public function __construct ()
{
// TODO Auto-generated constructor
}
/**
* Tests IndexController->init()
*/
public function testInit ()
{
// TODO Auto-generated IndexControllerTest->testInit()
$this->markTestIncomplete("init test not implemented");
$this->IndexController->init(/* parameters */);
}
/**
* Tests IndexController->indexAction()
*/
public function testIndexAction ()
{
// TODO Auto-generated IndexControllerTest->testIndexAction()
$this->markTestIncomplete("indexAction test not implemented");
$this->IndexController->indexAction(/* parameters */);
}
}
我该如何解决这个问题?
【问题讨论】:
-
你是如何运行测试的?您是否执行了“右键单击脚本”>“运行方式”>“PHPUnit 测试”?
-
是的,这正是我所做的。
-
删除 parent:: 调用并再试一次,尽管这不应该是错误的原因(调用只是不需要)。我有时会遇到这个错误,但是当我第二次重新运行测试时它通常会消失。
-
我刚刚做了,我得到了同样的东西。 :(
-
嗯,奇怪。我可以很好地运行测试(用 IndexController 代替 StdClass)。可以重启 Zend Studio 吗?您是否在命令行中安装了 PHPUnit 并可以从那里查看它是否工作?
标签: php unit-testing zend-framework phpunit zend-studio