C++模拟/测试 boost::asio::io_stream - 基于异步处理程序
在使用 C# 多年之后,我最近又回到了 C/C++。在那些年里,我发现了模拟和单元测试的价值。
在 C# 中查找模拟和单元测试的资源很简单。 WRT 模拟,C++ 则不然。
我想要一些关于其他人如何使用 boost 来模拟和测试异步 io_service 处理程序的指导。
例如,在 C# 中,我将使用 MemoryStream 来模拟 IO.Stream,并假设这是我应该在此处采用的路径。
- C++ 模拟/测试最佳实践
- boost::asio::io_service 模拟/测试最佳实践
- C++ 异步处理程序模拟/测试最佳实践
我已经使用 googlemock 和 googletest 开始了这个过程。
I've recently returned to C/C++ after years of C#. During those years I've found the value of Mocking and Unit testing.
Finding resources for Mocks and Units tests in C# is trivial. WRT Mocking, not so much with C++.
I would like some guidance on what others do to mock and test Asynch io_service handlers with boost.
For instance, in C# I would use a MemoryStream to mock an IO.Stream, and am assuming this is the path I should take here.
- C++ Mock/Test best practices
- boost::asio::io_service Mock/Test best practices
- C++ Async Handler Mock/Test best practices
I've started the process with googlemock and googletest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能已经发现,在 C++ 中进行模拟的帮助比在 C# 或 Java 中少得多。就我个人而言,我倾向于在需要时编写自己的模拟,而不是使用框架。由于我的大多数设计往往侧重于界面,这对我来说并不是特别困难,而且我倾向于构建一个与我正在开发的代码相匹配的“模拟库”。有关我如何做事的示例可以在此处在我的“实际测试”文章。最后,这与 C# 中的模拟和测试没有什么不同,所有相同的原则都适用,只是您最终需要自己完成更多繁重的工作。
As you've probably found already, there's much less help for mocking in C++ than in C# or Java. Personally I tend to write my own mocks as and when I need them rather than use a framework. Since most of my designs tend to be heavy on the interfaces this isn't especially difficult for me and I tend to build up a 'mock library' that goes with the code that I'm developing. An example of how I do things can be found here in my 'Practical testing' articles. In the end it's not that different to mocking and testing in C#, all of the same principles apply, you just end up doing more of the heavy lifting yourself.