Java: Unit testing image manipulations
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 insta开发者_JAVA百科nce, once I faced a problem when GIF images became color-inverted after reading them with ImageIO
and saving back.
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 - Image comparison - fast algorithm
精彩评论