我正在嘗試創建我的第一個單元測試。我使用Zend Studio的,和我已經打算加入PHPUnit的庫到我的項目: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測試」? – Gordon 2011-05-04 17:22:53
是的,這正是我所做的。 – 2011-05-04 17:27:15
刪除父::調用,然後再試一次,雖然這不應該是錯誤的原因(調用不需要)。我不時有這個錯誤,但當我第二次重新運行測試時,它通常會消失。 – Gordon 2011-05-04 17:29:15