phpUnit
phpUnitを入れてみる。
pearでインストール。
インストールコマンドは、いろいろなところに書いてあるので略。
- version
- PHPUnit 3.6.12 by Sebastian Bergmann.
とりあえず作ってみる。
- テストケースの作成
- http://www.atmarkit.co.jp/fcoding/articles/phptest/02/phptest02b.htmlを参考に。
- 家計簿アプリを作っている途中で、Billというクラスがあるので、それをテストすることにしてみる。
bill = new Bill;
}
public function testGetStandardHtml(){
$result = $this->bill->getStandardHtml();
$ret = "";
$ret .= "id=" . $this->bill->id . "
";
$ret .= "合計=" . $this->bill->sum . "
";
$ret .= "カード=" . $this->bill->file_prefix . "
";
$this->assertEquals($ret, $result);
}
}?>
- 実行してみる
$ phpunit BillTest
PHPUnit 3.6.12 by Sebastian Bergmann..
Time: 0 seconds, Memory: 4.50Mb
OK (1 test, 1 assertion)
- 3.6の日本語マニュアルはこちら。