I would be interested in thoughts concerning
UnitTesting for Java Events. This problem came up when I was writing a
JavaBean which generated
PropertyChangeEvents. I would like to write tests for those but am not sure of the best approach using
JavaUnit. --
ChanningWalton
I create event listeners that receive events and append them to a Vector, along with information about which method was called, etc.
To test a class that generates events I create a Vector, create event listeners with a reference to the Vector, register the listeners with the event source to be tested and then exercise the event source's methods. I then check that the Vector contains the expected sequence of events. I usually write convenience methods for this which compare a static array of objects to an enumeration of the vector's elements.
--
NatPryce
There is some related discussion on
JournallingPattern.
CategoryTesting CategoryJava CategoryEvents