Results 1 to 2 of 2

Thread: A unit test for a method that takes a Stream

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    A unit test for a method that takes a Stream

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: A unit test for a method that takes a Stream

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width