PDA

Click to See Complete Forum and Search --> : A unit test for a method that takes a Stream


mendhak
Feb 1st, 2009, 08:58 AM
How would you write a unit test for a method that accepts a file stream and returns a byte array? Or a method that takes a file stream (of an image) and resizes it?

Does the unit test project need to have a dummy file always-at-hand for this (that's what I'm doing right no)? I somehow don't find this to be a very... appealing solution. So I'm wondering if you guys have another way that you use.

jmcilhinney
May 8th, 2009, 01:53 AM
If your method accepted a Stream rather than a FileStream, then you could pass it a MemoryStream during testing instead.

That said, you can't always generalise and abstract your tests from your application. Having an image file in the test project may be the best way to go.