后還需要一個(gè)運(yùn)行測(cè)試的程序
CODE:
----------runtest.php-----------
require_once 'testcase.php';
require_once 'PHPUnit.php';
$suite = new PHPUnit_TestSuite("foTest");
$result = PHPUnit::run($suite);
echo $result->;toString();
?>;
現(xiàn)在可以通過命令行運(yùn)行這個(gè)testcase
php runtest.php
得到結(jié)果如下:
CODE:
TestCase foTest->;testFormatn1() passed
TestCase foTest->;testFormatn2() passed
TestCase foTest->;testFormatn3() passed
TestCase foTest->;testFormatn4() passed
TestCase foTest->;testFormatn5() passed
TestCase foTest->;testFormatn7() passed
TestCase foTest->;testFormatn8() passed
TestCase foTest->;testFormatn9() passed
TestCase foTest->;testFormatn10() passed
TestCase foTest->;testFormatn11() passed
TestCase foTest->;testFormatn12() passed
TestCase foTest->;testFormatn13() passed
TestCase foTest->;testFormatn6() failed: expected TRUE, actual FALSE
其中testFormatn6的測(cè)試失敗,
我們可以去檢查一下我們的代碼在什么地方出問題了。
補(bǔ)充一點(diǎn)
也可以把a(bǔ)ssertTrue方法換assertEquals,如下:
CODE:
function testFormatn6() {
$result = $this->;abc->;formatn("1343");
$expected = "1343";
$this->;assertEquals($expected, $result);
}
如果失敗得到對(duì)應(yīng)的結(jié)果會(huì)直觀一些(可以顯示錯(cuò)誤的結(jié)果):
CODE:
TestCase foTest->;testFormatn8() failed: expected 1343 , actual 134.