PHPUnit3.2.2

PHPUnit

PHPのUnitTestフレームワークとして昔PEARにあったのが、なんか独立(?)してるみたい。

昔試し損ねたので今回試してみました。
環境はXAMPPでPHP5。どうもPHP5でないとこのバージョンは動かないらしいので。
PHP4に対しては別途どこかで試したいと思います。(2008年8月で完全にメンテナンスを止めるらしいので本当にやるかどうかは怪しいですが)

xamppでやってるので、windowsですがlinuxでもほぼ一緒です。

C:\xampp\php>pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

C:\xampp\php>pear install phpunit/PHPUnit
Did not download optional dependencies: pear/Image_GraphViz, pear/Log, use --all
deps to download automatically
phpunit/PHPUnit can optionally use package "pear/Image_GraphViz" (version >= 1.2
.1)
phpunit/PHPUnit can optionally use package "pear/Log"
phpunit/PHPUnit can optionally use PHP extension "pdo_sqlite"
phpunit/PHPUnit can optionally use PHP extension "xdebug" (version >= 2.0.0)
downloading PHPUnit-3.2.2.tgz ...
Starting to download PHPUnit-3.2.2.tgz (195,562 bytes)
.........................................done: 195,562 bytes
install ok: channel://pear.phpunit.de/PHPUnit-3.2.2

C:\xampp\php>


で試しに「PHPUnit3で始めるユニットテスト」を一通りやってみました。

感想は


  • そもそもPHP5になれてないのであれですが、LightWeightの良さがなんかなくなってきた気が

  • テストケース自体はJUnitとやらRubyやらとなんらかわらない

  • クラスからテストケースの雛形(と言ってもテストメソッドだけだけど)を作れるのは少しうれしい。

  • ふつうのアプリはモックでいろいろとテストできる。しそんなに難しくない

  • 一個ずつメソッドの戻り値を設定していくのもめんどくさい

  • PHPの本来の姿であるWebアプリでのテストの為のモックオブジェクトは?デフォルトで備わってるものとおもってた。

ざっと思い当たるまでを。


PHPUnit ポケットガイド