0

I'm currently testing with NUnit v2.5.10 a communication class on serial port. Each test that uses the "Write" method fails in running mode but pass in debugging. The test fails because the method write on ComPort only a portion of buffer.

How can I fix this behaviour? Any help will be welcome. Thank you in advance.

Alex

  • SerialPort provides no way to reliably detect how much was written. The Write() method doesn't have a return value. So your test is probably wrong. Nobody can see it from here. – Hans Passant Dec 15 '11 at 09:45

1 Answers1

3

When unit-testing a communication class you should not rely on the real SerialPort class. You should MOCK the behavior of the SerialPort to test all the different logic flows in your communication class. Use for example the moq framework to simulate and verify the behavior of the SerialPort.

See following question for more information.

Community
  • 1
  • 1
Tim Cools
  • 1,162
  • 10
  • 19