4

アプリケーションとテストの Java ソース コードをコンパイルし、アプリケーション クラスを計測し、JUnit テストを実行し、JUnit と Emma のコード カバレッジ レポートを生成する Ant ビルド ファイルがあります。JUnit タスクには、計測されたクラスへのパスが与えられます。

問題は、インターフェイスがインストルメント化されていないことです ( Emma FAQ ) が、テストでそれらを使用し、JUnit がそれらを見つけることができません。

私は2つの解決策を考えることができます:

  • テストでインターフェイスを使用しないでください(インターフェイスへのプログラミングに反します-テストでカウントされますか?)
  • インストルメント化されたクラスの横にインターフェイスをコピーします (インターフェイスへのパスをハードコーディングします)。

この問題にどのようにアプローチし、解決する必要がありますか?

4

1 に答える 1

4

It sounds to me as though you are saying that JUnit is having trouble because the interfaces are not on the class path?

The usual answer would be to put them there.

The quick and dirty answer might be to put the classpath for the not instrumented classes into the juint class path AFTER the path to the instrumented classes. The class loader should use the first match it finds, so the instrumented implementations will be consumed instead of the non-instrumented implementations, but the interfaces will still be available.

If that solves your problem, you may want to replace the quick and dirty with something more robust, like making the interfaces available in a jar that is separate from the implementation.

于 2010-07-01T22:37:06.813 に答える