单元测试命名管道

发布于 2024-09-15 11:23:56 字数 372 浏览 4 评论 0原文

对通过 NamedPipeServerStreams

我的想法是使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月牙弯弯 2024-09-22 11:23:56

我会编写一个接口,抽象出命名管道中难以测试的部分。

这个的实现相当简单(使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文