W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
Example?14.3, “簡(jiǎn)單的測(cè)試監(jiān)聽(tīng)器”展示了 PHPUnit_Framework_TestListener
接口的一個(gè)簡(jiǎn)單實(shí)現(xiàn)。
Example?14.3.?簡(jiǎn)單的測(cè)試監(jiān)聽(tīng)器
<?php
class SimpleTestListener implements PHPUnit_Framework_TestListener
{
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{
printf("Error while running test '%s'.\n", $test->getName());
}
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
{
printf("Test '%s' failed.\n", $test->getName());
}
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
printf("Test '%s' is incomplete.\n", $test->getName());
}
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
printf("Test '%s' is deemed risky.\n", $test->getName());
}
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
printf("Test '%s' has been skipped.\n", $test->getName());
}
public function startTest(PHPUnit_Framework_Test $test)
{
printf("Test '%s' started.\n", $test->getName());
}
public function endTest(PHPUnit_Framework_Test $test, $time)
{
printf("Test '%s' ended.\n", $test->getName());
}
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{
printf("TestSuite '%s' started.\n", $suite->getName());
}
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
printf("TestSuite '%s' ended.\n", $suite->getName());
}
}
?>
Example?14.4, “使用測(cè)試監(jiān)聽(tīng)器基類”展示了如何從抽象類 PHPUnit_Framework_BaseTestListener
派生子類,這個(gè)抽象類為所有接口方法提供了空白實(shí)現(xiàn),這樣你就只需要指定那些在你的使用情境下有意義的接口方法。
Example?14.4.?使用測(cè)試監(jiān)聽(tīng)器基類
<?php
class ShortTestListener extends PHPUnit_Framework_BaseTestListener
{
public function endTest(PHPUnit_Framework_Test $test, $time)
{
printf("Test '%s' ended.\n", $test->getName());
}
}
?>
在the section called “測(cè)試監(jiān)聽(tīng)器”中可以看到如何配置 PHPUnit 來(lái)將測(cè)試監(jiān)聽(tīng)器附加到測(cè)試執(zhí)行過(guò)程上。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: