views:

41

answers:

1

I have an Ant build file where I compile the Java source code of the application and of the tests, instrument the application classes, run JUnit tests and generate JUnit and Emma code coverage reports. The JUnit task is given the path to the instrumented classes.

The problem is that the interfaces are not instrumented (Emma FAQ) but I use them in the tests and JUnit can't find them.

I can think of 2 solutions:

  • don't use interfaces in tests (goes against programming to interfaces - does it count in tests?)
  • copy the interfaces next to the instrumented classes (hard-coding the path to the interfaces)

How should I approach and solve this problem?

+1  A: 

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.

VoiceOfUnreason
Including the non-instrumented classes after the instrumented ones worked, thanks.