Test for images

I have created a package that outputs images, and now I want to create a bunch of tests for the package. I know, the tests should have been created much earlier, and not when I am almost done with the package, but it is what it is :slight_smile:

So, my question is : How do you create tests when the output are images? Sure, I can compare the bytes of a stored correct image and the output image, and if they match, everything is ok.

But, according to my initial testing, every newly created image (in my case PNG:s) is different from the previously created image. It looks like there is A LOT of changes in the files, not just meta data, like created date etc, when I compare the images with meld. The images are visually identical though, and that is what I want to test, the visual part.

To me, it sounds like this must be a problem that other people have had? So how do you create tests for image outputs?

Its not really important what my package does, but for reference, it creates images of chess boards : GitHub - Hultan/chessImager: ChessImager is a Go package that creates images of chess boards based on a FEN string. It is highly configurable, so that you can create chess board images that look exactly the way you want them to look.

I might have done something stupid when I did my initial testing. Now I don’t see any changes in the image, after creating it a second time.

So, it looks like it is possible to compare the images, byte by byte.

Hi @Hultan, how are you?
I have migrated a service from Java to Go converting images in different formats.
To compare the results, we made an small script that gets and image from both services and compare them.
Here are some tecniques:

Interesting, I think though, that in my case I only need to check for exact matches. So then it should be faster to just compare bytes by bytes, I think, rather that doing a bunch of math on each pixel.

I don’t need to know if it is close, it should be a match or not.

Sure, BUT if you change anything in your code, you should change all the tests.
You can’t upgrade your component that generate the images, for example.

Hmm, you might be correct, we’ll see when I finished a couple of test. Maybe there are cases where I need near-matches.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.