XML Feeds

.

[java-dev] Re: Re: Re: Unit testing Java externals that call outlet()

Adam Murray adamjmurray at gmail.com
Mon Aug 13 15:00:02 MDT 2007


If anyone else is wondering how to test their Java externals, here's what I ended up doing:

I made my own method output() that is the only code in my external allowed to call outlet(). This turns out to have some benefits, because I can make overloaded forms of output() that handle different internal message formats and convert them into the format needed for outlet() (like Atom[]). 

Then, in my unit tests, I have a class that subclasses the external I am testing, and overrides output() to do nothing. All my tests instantiate the subclass instead of the real external class. The only downside is this has to be done for each external, but it's not much work unless you need to refactor existing code that has outlet() calls all over the place.

There are definitely some other good ideas in this thread, but this approach seemed to be the easiest and most straightforward. 

Also, in an earlier post I mentioned an issue with calling System.out. This can easily be corrected by doing this when the unit test initializes:
PrintStream out = System.out;
And then use "out" for any debugging purposes. Same applies to System.err. I think as soon as you construct any MaxObject, these streams will be "stolen".

Adam


More information about the java-dev mailing list