metova/MetovaTestKit

Add image comparison assertions

wibs opened this issue · 1 comments

wibs commented

Although iOS seems to compare image assets correctly if they are loaded using the imageNamed function on UIImage, this only works because iOS uses the same image in memory for those objects. If the same image is loaded from another source (from the file system, using SDWebImage, etc.), this comparison will not work. To avoid this confusing scenario, an assertion should be added that compares the image data so we can know that two images are identical.

This implementation will require converting to data and comparing the data objects. I recommend the assertion takes an enum that allows you to specify if the image should be compared by converting to png or jpg, and the jpg enum case allows an associated value representing the compression to use. (Think of this like XCTAssertEqualWithAccuracy for comparing floating point types.) However, the argument should be optional and should default to png, as that is a loss-less conversion.