4. Q : 什 麼 是 單 元 測 試 ?!
A:
程式語言裡 , 單元測試是由專案程式碼各個區塊受測試是
否可使用的方法 , 它也是軟體測試最小單位
In computer programming, unit testing is a method by
which individual units of source code are tested to
determine if they are fit for use. A unit is smallest testable
part of an application. - Wiki
19. Mock 物件實做
class SomeClass
{
public function doSomething()
{
// Do something.
}
}
class StubTest extends PHPUnit_Framework_TestCase
{
public function testStub()
{
$stub = $this->getMock('SomeClass');
$stub->expects($this->any())
->method('doSomething')
->will($this->returnValue('foo'));
$this->assertEquals('foo', $stub->doSomething());
}
}