Re: Test driven design and graphics in Java
Kenneth P. Turvey wrote:
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?