5
這是我的PHPUnit測試文件phpunit運行兩次測試 - 獲得兩個答案。爲什麼?
<?php // DemoTest - test to prove the point
function __autoload($className) {
// pick file up from current directory
$f = $className.'.php';
require_once $f;
}
class DemoTest extends PHPUnit_Framework_TestCase {
// call same test twice - det different results
function test01() {
$this->controller = new demo();
ob_start();
$this->controller->handleit();
$result = ob_get_clean();
$expect = 'Actions is an array';
$this->assertEquals($expect,$result);
}
function test02() {
$this->test01();
}
}
?>
這是在測試
<?php // demo.php
global $actions;
$actions=array('one','two','three');
class demo {
function handleit() {
global $actions;
if (is_null($actions)) {
print "Actions is null";
} else {
print('Actions is an array');
}
}
}
?>
文件的結果是,因爲$行爲是無效的第二次測試失敗。
我的問題是 - 爲什麼我沒有得到兩個測試相同的結果?
這是phpunit中的錯誤還是我對php的理解?
多麼好的答案 - 謝謝。它現在變得非常靈敏。 – Ian 2010-10-12 09:32:24