I'm looking for direction on how to test that a dynamically generated image is the expected image with JUnit. A bit of background:
I have code that generates thumbnail images as java.awt.image.BufferedImage's and stores those BufferedImages into a java.io.File object.
I wrote a simple unit test to check a few key items in order to gain confidence that the generated image was correct:
@Test
public void testGenerateDefaultThumbnail() {
File file = // someGeneratedFile.jpg
assertNotNull(file);
assertEquals(10211l, file.length());
}
Basically, I'm just confirming that the file size is what I expect.
This works fine locally on my machine (Mac OSX), but as soon as our tests run on our build server (Ubuntu), one of the tests is failing with the following:
java.lang.AssertionError: expected:<10211> but was:<10158>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:743)
at org.junit.Assert.assertEquals(Assert.java:118)
at org.junit.Assert.assertEquals(Assert.java:555)
at org.junit.Assert.assertEquals(Assert.java:542)
at c.v.t.ThumbnailTest.testGenerateDefaultThumbnail(ThumbnailTest.java:53)
Three part question:
- Why may the file size be different for an image across OS's?
- Is there a standard approach to unit testing image generation?
- Should I change my approach to compare two File objects (where a pre-generated file exists as a resource in the project)?
Thanks!