A Set of Unit Testing Rules

http://www.artima.com/weblogs/viewpost.jsp?thread=126923

A test is not a unit test if:

  • 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.

Tests that do these things aren't bad. Often they are worth writing, and they can be written in a unit test harness. However, it is important to be able to separate them from true unit tests so that we can keep a set of tests that we can run fast whenever we make our changes.

    • -

各クラスのホワイトボックステストを意図するユニットテストと、クラス外に依存するテストを明確に分ける必要はありますね。

例えば、ファイルシステム用のユーティリティクラスなどは、実際にファイルシステムを操作するユニットテストが非常に有効だし、必須だと思います。しかし、通常の開発プロジェクトのビルドに含まれるというのには違和感があります。

クラス外に依存するテストは全てインフラストラクチャ的な位置づけ(Domain Driven Design で言うところのインフラストラクチャレイヤ)と考えると、ライブラリとして開発プロジェクト外で管理するのが妥当かもしれません。
# クラス外に依存するテストで、ホワイトボックステストで、インフラストラクチャ的な位置づけでないものってあるのか? すぐには思いつかないが。