Thread overview
Unit tests for I/O functions
Apr 28, 2007
Jason House
Apr 28, 2007
BCS
Apr 28, 2007
Jason House
April 28, 2007
If I have a class that reads from an InputStream and writes to an OutputStream, what is the recommended method for writing a unit test for sending commands in one stream and testing its output of the other stream?  Would a pair of MemoryStream's be most appropriate?
April 28, 2007
Reply to Jason,

> If I have a class that reads from an InputStream and writes to an
> OutputStream, what is the recommended method for writing a unit test
> for sending commands in one stream and testing its output of the other
> stream?  Would a pair of MemoryStream's be most appropriate?
> 

that's what I do.


April 28, 2007
BCS wrote:
> Reply to Jason,
> 
>> If I have a class that reads from an InputStream and writes to an
>> OutputStream, what is the recommended method for writing a unit test
>> for sending commands in one stream and testing its output of the other
>> stream?  Would a pair of MemoryStream's be most appropriate?
>>
> 
> that's what I do.
> 
> 

So far, I haven't had any success with the unit tests even though the normal usage works fine...

The thread's run function has something to the effect of:
while(1){
  char[] command = inStream.readLine();
  process(command);
}

It seems that readLine does not block with a memoryStream like it does with din and dout.  What's the best work around?


PS: I tried the following but had no luck.  process(command) never got called after the unit test wrote to the stream (with writefln):

while(1){
  char[] command = inStream.readLine();
  if (command.length == 0)
    continue;
  process(command);
}