A Set of Unit Testing Rules

Michael Feathersは以下のようなものはユニットテストではないといっている。

* It talks to the database
* It communicates across the network
* It touches the file system
* It can't run at the same time as any of your other unit tests
* You have to do special things to your environment (such as editing config files) to run it.

後半の二つはともかく、最初の三つには賛成できない。データベースとアクセスする責務をもつクラスのユニットテストは実際にアクセスすべきだと思う。外部(何が外部かって定義はおいといて)と隣接するインフラ的なレイヤを設けて、そうではない部分のクラスからはデータベースにアクセスするなって言うべきではないのかなぁ。まあ、Cedric Beustがいうように言葉遊びなのかもしれないけど。Cedricは他にも興味深い指摘をしている。

The bottom line is that the success of JUnit has shown that the line between unit and non-unit tests is increasingly being blurred.

http://d.hatena.ne.jp/t-wada/20050823#1124786951http://jroller.com/page/njain?entry=types_of_tests_on_agile の分類では、まだまだ粗いってことか。