<?php public function testThisMightHaveADb() { $myObject->createObject(); try { $db = new Database(); $this->assertTrue($db->rowExists()); } catch (DatabseException $e) { $this->markTestSkipped(''This test was skipped because there was a database problem''); } } ?>
<?php public function testAreNotEnoughHours() { $this->markTestIncomplete("There aren''t enough hours in the day to have my tests go green"); $trueVariable = true; $this->assertTrue($trueVariable); } ?>
<?php class Testable { public $trueProperty = true; public $resetMe = true; public $testArray = array( ''first key'' => 1, ''second key'' => 2 ); private $testString = "I do love me some strings"; public function __construct() { } public function addValues($valueOne,$valueTwo) { return $valueOne+$valueTwo; } public function getTestString() { return $this->testString; } } ?>
我们编写的单元测试代码初步的框架如下:
<?php class TestableTest extends PHPUnit_Framework_TestCase { private
PHP单元测试利器:PHPUNIT深入用法(二) - 凌众科技