我開始學習PhpUnit並進行測試。我有一個返回字符串的方法,我如何編寫一個測試來檢查這個方法是否返回字符串。下面是我在這一刻代碼:PhpUnit和字符串
方法:
/**
* @return string
*/
public function living()
{
return 'Happy!';
}
測試:
public $real;
public $expected;
public function testLiving()
{
$this->expected = 'Happy';
$this->real = 'Speechless';
$this->assertTrue($this->expected == $this->real);
}
它們在通過時是一樣的,但是當assertEquals失敗時,它會告訴你它們在哪裏,而assertTrue會告訴你false是不正確的。 – gontrollez 2014-11-04 13:47:28