[英]How do I run all my PHPUnit tests?
我有一個名為Script.php的腳本並在Tests / Script.php中對它進行測試,但是當我運行phpunit時測試它不會在我的測試文件中執行任何測試。 如何使用phpunit運行所有測試?
PHPUnit 3.3.17,PHP 5.2.6-3ubuntu4.2,最新的Ubuntu
輸出:
$ phpunit Tests
PHPUnit 3.3.17 by Sebastian Bergmann.
Time: 0 seconds
OK (0 tests, 0 assertions)
這是我的腳本和測試文件:
script.php的
<?php
function returnsTrue() {
return TRUE;
}
?>
測試/ script.php的
<?php
require_once 'PHPUnit/Framework.php';
require_once 'Script.php'
class TestingOne extends PHPUnit_Framework_TestCase
{
public function testTrue()
{
$this->assertEquals(TRUE, returnsTrue());
}
public function testFalse()
{
$this->assertEquals(FALSE, returnsTrue());
}
}
class TestingTwo extends PHPUnit_Framework_TestCase
{
public function testTrue()
{
$this->assertEquals(TRUE, returnsTrue());
}
public function testFalse()
{
$this->assertEquals(FALSE, returnsTrue());
}
}
?>
Php test的文件名必須以Test.php結尾
phpunit mydir
將在目錄mydir中運行名為xxxxTest.php
所有腳本
(看起來喜歡它沒有在phpunit文檔中描述)
我創建了以下phpunit.xml ,現在至少我可以在我的根目錄中執行phpunit --configuration phpunit.xml來運行位於Tests /中的測試
<phpunit backupGlobals="false"
backupStaticAttributes="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Tests">
<directory suffix=".php">Tests</directory>
</testsuite>
</testsuites>
</phpunit>
我認為forPHPUnit決定自動運行它必須遵循文件名約定:somethingTest.php。
你認為他們會記錄這一點。 我只是查看了手冊,他們說你可以傳遞一個目錄,但實際上並不是如何做到的。
也許你的類名必須匹配測試腳本文件名的基本名稱(除了“.php”之外的所有內容)?
<?php
//Files required for phpunit test
require_once 'PHPUnit/Framework.php';
//Knowing the drupal environment
require_once './includes/bootstrap.inc'; //initialize the Drupal framework
//Loading the drupal bootstrap
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//Helper file
include_once 'helper.inc';
//Including inc file of addresses module
include_once(module_load_include('inc','addresses_user','addresses_user'));
class addresses_test extends PHPUnit_Framework_TestCase {
protected $uid;
protected function setUp()
{
$this->uid = 1;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.