> In other words, don't test "User Clicks Button". test "Event Fired When
> User Clicks Button"

Signature
Kenneth P. Turvey <kt-usenet@squeakydolphin.com>
> I understand all this, but I'm really working on a graphical
> application. The problem isn't really to test whether a single event is
> fired. The problem is to determine if an image has been altered
> correctly when a certain sequence of events happen... or something
> similar.
I may not be understanding correctly here, but the first thing that
occurs to me is to yoink the methods that perform these graphical
calculations out of the view, and place them in a separate class that
can be tested easily. Get rid of the Graphic2D object and other Swing
objects (although you might have to keep Image).
Then once that class is unit tested, it becomes a matter of integration
testing when you compose the view with a real graphics object, but that
can be done much more coarsely.
I think is see what you mean by "test is similar the method being
tested." To test if a method makes an Image 50% darker, you need an
image that's 50% darker to test against. Hmmm, not sure there's a way
around that....
You might want to be concerned with things like boundary conditions
(memory, pointers, indexing) in the unit test and use some other method
for the calculations themselves. Code review + mathematical proof perhaps?
Lew - 19 Apr 2008 04:02 GMT
> I think is see what you mean by "test is similar the method being
> tested." To test if a method makes an Image 50% darker, you need an
> image that's 50% darker to test against. Hmmm, not sure there's a way
> around that....
What does "50% darker" mean, hmm? Some guy looks at it and says, "Yup, that's
50%!" Then his brother says, "No, it ain't!" Then Aunt Tilly says, "Why is
that picture so dark? Sonny, turn up the brightness, will you?"
How do you know if you've made the picture darker, let alone 50%? Dollars to
donuts it's via a testable condition, such as, oh, given a certain HSB value,
the new B is half the old value. Then you devise a test that fires the
trigger you expect the "darken 50%" button to fire, and compare the resultant
image's (average) B to the original value, and see if it's half.
Automatically. Then all you have to test the GUI for is that it fires the
correct event, not even connect that test to images at all.

Signature
Lew