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