title: Testing image files with JUnit
body: <p>I'm looking for direction on how to test that a dynamically generated image is the expected image with JUnit. A bit of background:</p>
  
  <p>I have code that generates thumbnail images as java.awt.image.BufferedImage's and stores those BufferedImages into a java.io.File object.</p>
  
  <p>I wrote a simple unit test to check a few key items in order to gain confidence that the generated image was correct:</p>
  
  <pre><code>@Test
  public void testGenerateDefaultThumbnail() {
      File file = // someGeneratedFile.jpg
  
      assertNotNull(file);
      assertEquals(10211l, file.length());
  }
  </code></pre>
  
  <p>Basically, I'm just confirming that the file size is what I expect.</p>
  
  <p>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:</p>
  
  <pre><code>java.lang.AssertionError: expected:&lt;10211&gt; but was:&lt;10158&gt;
    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)
  </code></pre>
  
  <p>Three part question:</p>
  
  <ul>
  <li>Why may the file size be different for an image across OS's?</li>
  <li>Is there a standard approach to unit testing image generation?</li>
  <li>Should I change my approach to compare two File objects (where a pre-generated file exists as a resource in the project)?</li>
  </ul>
  
  <p>Thanks!</p>