单元测试命名管道
我的想法是使用 NamedPipeClientStream单元测试,但测试最终挂起;我怀疑这是因为他们都处于同一过程中。
What is the recommended way to unit test an object that publishes via NamedPipeServerStreams?
My thought was to use a NamedPipeClientStream in the unit test but the test just ends up hanging; I suspect this is due to both of them being in the same process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会编写一个接口,抽象出命名管道中难以测试的部分。
这个的实现相当简单(使用 NamedPipe...api),我不会对其进行单元测试。
完成后,我在应用程序代码中使用该接口。我在测试代码中有一个模拟实现,并且我将使用模拟对象在管道上执行操作。
例如,我的界面将有一个 ClientConnected 事件,公开有关客户端的一些数据。
然后,我在模拟对象中实现此接口,并让它引发客户端连接事件,并断言应用程序在客户端连接时执行了正确的操作。
HTH。
I would write an interface that abstracts away the hard to test parts of the named pipe.
The implementation of this would be fairly straightforward (using the NamedPipe... apis) and I wouldn't unit test that.
Once thats done I use the interface in the application code. I'd have a mock implementation in the test code and I would use the mock object to do stuff on the pipe.
E.g. my interface would have a ClientConnected event exposing some data about the client.
I'd then implement this interface in a mock object and have it raise the client connected event and assert that the application did the correct things when the client was connected.
HTH.