We've written a library that generates thumbnails for various file formats. I like to unit test this library. It generates JPEG files.
How would I unit test an image conversion? How can I check if two images look alike when JPG uses a lossy format?
Microsoft TestTools has an ImageCompare class, but I'm not sure if it fits my profile. Any ideas?
First of all, your unit test does not expose actual implementation. You use mocks. The goal should be to verify that methods are called and given mock implementation returns expected result.
Often people mix unit test with integration tests and have problems with responsibility in general. What you described seems to be an integration test.
One way would be to create an ImageDifference function to get mean difference:

Images are taken from Wolfram Mathematica documentation. Given correct tools and pre-knowledge this is a really easy problem (but very often it is not).
In the case of a lossy image, you would get something that looks like a shadow image. However, you do not need to compute the image, just a double describing the difference. To test it:
Assert.That(expected, Is.EqualTo(actual).Within(tolerance));
Let's say that your expected is 0.03 and actual are 0.01638489638 and tolerance is 0.005. That would test if an image contains 97% quality image with 0.5% error.
I hope you found this was helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With