1

I have an array of pixels which I wish to save to an image file. Python appears to have a few libraries which can do this for me, so I'm going to use one of them, passing in my pixel array and using functions I didn't write to write the image headers and data to disk.

How do I do unit testing for this situation?

I can:

  • Test that the pixel array I'm passing to the external library is what I expect it to be.
  • Test that the external library functions I call give me the expected return values.
  • Manually verify that the image looks like I'm expecting (by opening the image and eyeballing it).

I can't:

  • Test that the image file is correct. To do that I'd have to either generate an image to compare to (but how do I generate that 'trustworthy' image?), or write a unit-testable image-writing module (so I wouldn't need to bother with the external library at all).

Is this enough to provide coverage for my code? Is testing the interface between my code and the external library sufficient, leaving me to trust that the output of the external library (the image file) is correct through manual eyeballing?

How do you write unit tests to ensure that the external libraries you use do what you expect them to?

1 Answer 1

3

Bit old on Python.

But this is how I would approach it.

Grab the image doing a manual test. Compute a check sum (MD5 perhaps). Then the automated tests need to compare it by computing the MD5 (in this example) with the one done on the manual test.

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.