}
最后还需要一个运行测试的程序
CODE:
----------runtest.php-----------
require_once 'testcase.php';
require_once 'PHPUnit.php';
$suite = new PHPUnit_TestSuite("foTest");
$result = PHPUnit::run($suite);
echo $result->;toString();
?>;
require_once 'testcase.php';
require_once 'PHPUnit.php';
$suite = new PHPUnit_TestSuite("foTest");
$result = PHPUnit::run($suite);
echo $result->;toString();
?>;
现在就可以通过命令行运行这个testcase
php runtest.php
得到结果如下:
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
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的测试失败,
我们就可以去检查一下我们的代码在什么地方出问题了。
补充一点
也可以把assertTrue方法换assertEquals,如下:
CODE:
function testFormatn6() {
$result = $this->;abc->;formatn("1343");
$expected = "1343";
$this->;assertEquals($expected, $result);
}
$result = $this->;abc->;formatn("1343");
$expected = "1343";
$this->;assertEquals($expected, $result);
}
如果失败得到对应的结果会直观一些(可以显示错误的结果):
CODE:
TestCase foTest->;testFormatn8() failed: expected 1343 , actual 134.
文章来源于领测软件测试网 https://www.ltesting.net/