简体   繁体   English

测试SerialPort通信

[英]Testing SerialPort communication

I'm currently testing with NUnit v2.5.10 a communication class on serial port. 我目前正在使用NUnit v2.5.10在串行端口上测试通信类。 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. 测试失败,因为该方法仅在ComPort上写入缓冲区的一部分。

How can I fix this behaviour? 我该如何解决此问题? Any help will be welcome. 任何帮助都将受到欢迎。 Thank you in advance. 先感谢您。

Alex 亚历克斯

When unit-testing a communication class you should not rely on the real SerialPort class. 在对通信类进行单元测试时,您不应依赖于真正的SerialPort类。 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. 例如,使用moq框架来模拟和验证SerialPort的行为。

See following question for more information. 有关更多信息,请参见以下问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM