views:

54

answers:

1

I have a method that deals with an image. The method takes one image, performs some manipulations over it and returns another image:

public BufferedImage manipulateImage (Image image) {
    ...
}

I'm not sure if there are any best practices of writing unit tests for such activities. What characteristics of the image should be checked at a first place? How to check if the image was not spoiled? For instance, once I faced a problem when GIF images became color-inverted after reading them with ImageIO and saving back.

+1  A: 

Get your original image (x), run the transform and save the manipulated image (y), physically check yourself that y is what you want to test. Your test is then that F(x) = y, if you have both x and y in your src/test/resources directory you can compare y to the output of your test.

You may also be interested in http://pdiff.sourceforge.net/ (C++ not Java) should you not need to test for 100% equality.

Edit: also see this question - http://stackoverflow.com/questions/843972/image-comparison-fast-algorithm

Jon Freedman
+1 - very useful references
denis_k