0

I would like to test my thumb generator which retuns byte[] of content in ".png". The test would generate a thumb and then display the thumb image. For example:

byte[] thumbContent = myThumbGenerator.generateThumb("source_image.png", dimensions); AnyConvenientImageViewerUtil.showPNGImage(thumbContent);

Does anybody knows any convienient util class/library to achieve this in that way?

I know that I could achieve this by creating JFrame and so on... but I don't want to reinvent the wheel.

Thanks in advance.

Dawid Naczke
  • 1,144
  • 12
  • 11
  • Add a `JLabel` (in a `JScrollPane` if needed) to a `JOptionPane`? – MadProgrammer Dec 19 '14 at 10:38
  • 2
    Why does a unit test need to display anything at all? It should be automatic and require no human interaction. – Duncan Jones Dec 19 '14 at 13:15
  • @Duncan If a unit test fails, it's often useful to see how the result differs from what was expected. For images, a visual representation often makes the error easier to spot than looking at thousands of raw bytes... :-) I sometimes do this in my tests (with fallback to byte diff if in headless mode). – Harald K Dec 19 '14 at 21:42

1 Answers1

1

All unit tests should be self verifying without human intervention. Ideally it should also be able to run "headless" without anything other than a commandline terminal (no GUI).

Since you are providing the input image. The test should also provide a correct thumbnail file to compare against.

byte[] thumbContent = myThumbGenerator.generateThumb("source_image.png", dimensions);

byte[] expectedThumbnailValue = ...

//check byte for byte comparison
assertArrayEquals(expectedThumbnailValue, thumbContent)
dkatzel
  • 31,188
  • 3
  • 63
  • 67