开发者

How to simulate a serial port failure?

Working on a library which communicates with a range of USB devices I want to develop a suite of API tests to check the integration status of new devices. One of the situations I wish to test is unexpected device removal. Short of creating breakpoints in the test script where the device must be manually unplugged/replugged I would like to be able to simulate this behaviour programattically.

Currently I am simulating this with Devcon but the problem I am facing is that if the API has already connected to the device on an open serial port Devcon cannot close that serial port and so I cannot fully simulate device removal, even though all of the devices manifestations in Device Manager apart from the remaining COM port are removed.

I have been unable to find a solution in my research effort so far, and wondered if anyone had encountered the same problem/knows of a solution.

(Language is c#, .Net2开发者_StackOverflow中文版.0)


this might be not exactly an answer to your question, but I would do the following: Refactor every access to real hardware/devices into interfaces and inject them as dependencies into your code. Now you can mock those interfaces and do unit-testing as you like.

To make integration/real test to the real thing and indeed unplug/plug, etc. the hard way.

This works fine for me and for many others I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜