如何衡量模拟框架 (TypeMock) 的开销?
我刚刚开始为我的团队评估模拟框架,想知道是否有人有任何关于参考文档或经验的指示,您可以分享有关进行性能测试时模拟成本的信息。
链接? 个人经验? 细节赞赏。
I'm just beginning to evaluate mocking frameworks for my team and am wondering if anyone has any pointers to reference documentation or experience that you can share regarding the cost of mocking when doing performance tests.
Links? Personal experience? Details appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
IIRC TypeMock 使用 Profiler API,这通常会增加相当多的开销,但仍然比通过分析器运行应用程序更快。
Ncover 还使用 Profiler API,而且速度似乎相当快。
IIRC TypeMock uses the Profiler API, which generally does add quite a bit of overhead, but should still be faster than running the application via a profiler.
NCover also uses the Profiler API, and seems to be quite fast.
Aaron Jensen 创建了一个测试项目并进行了一些性能测试。 http://codebetter.com/ blogs/aaron.jensen/archive/2008/05/08/mock-framework-benchmarks.aspx
我宁愿根据 API 和功能进行选择,但性能可能是 TDD 和运行测试负载的问题次。
Aaron Jensen created a test project and did some performance testing. http://codebetter.com/blogs/aaron.jensen/archive/2008/05/08/mock-framework-benchmarks.aspx
I'd rather choose based on API and capabilities though, but performance can be an issue with TDD and running your tests loads of times.
我们已经使用 TypeMock 几年了,根据我的经验,性能上没有显着的开销(我确信有开销,这不是一个大问题)。
然而,由于 TypeMock 工作方式的本质,有几件事需要考虑。 由于 TypeMock 基本上是通过动态注入代码来工作的,因此错误有时可能非常奇特。 因此,报告错误可能会成为一项艰巨的任务。 准备好深入了解 IL。
我的经验是,向“普通开发人员”解释 TypeMock 的工作原理可能很困难。 它很快就会变得复杂,尽管他们的跟踪工具使故障排除变得可行,但仍然留下了一些支持任务。
此外,由于 TypeMock 允许您模拟任何内容(除了 mscorlib),因此您实际上不需要向代码添加必要的间接级别。 这是一个功能,TypeMock 并没有真正的错误。 尽管如此,我还是看到很多开发人员试图通过到处模拟来解决他们的问题,而不是解耦代码。 在我看来,这并不能提高整体代码质量。
We have been using TypeMock for a couple of years and in my experience there is no significant overhead in performance (I'm sure there is an overhead, it is just not a big issue).
However, due to the nature of how TypeMock works there are several things to consider. As TypeMock basically works by injecting code on the fly the errors can sometimes be very exotic. Reporting errors can thus become a bit of a daunting task. Be prepared to dig into IL.
My experience is that it can be hard to explain the "average developer" how TypeMock works. It quickly becomes complicated and even though their Trace tools make troubleshooting doable it still leaves a bit of a support task.
Also, as TypeMock will let you mock anything (except for mscorlib), you don't really need to add the necessary levels of indirection to your code. This is a feature and TypeMock is not really at fault here. Still, I've seen a lot of developers trying to solve their problems by mocking all over the place instead of decoupling the code. That doesn't improve the overall code quality IMO.
我一直在测试模拟框架(特别是 Moq 和 TypeMock)。 TypeMock 更加强大和灵活,但由于它作为分析器插入到框架中,因此确实对性能产生了重大影响。
我的结论是,TypeMock 是非负载测试场景的优秀工具。 起订量不太灵活……但重量轻得多,并且不会对总体性能产生广泛影响。 使用 Moq,您必须专门设置您的应用程序,以便能够模拟外部依赖项(无论如何都是良好设计的练习),但事实证明它更适合我的负载相关场景。
不幸的是,我没有在关于 Moq 与 TypeMock 的测试中记录实际数字,但根据我的经验,Moq 的性能优势是显着的。
I have been testing mocking frameworks (Moq and TypeMock specifically). TypeMock is much more powerful and flexible but because it plugs into the framework as a profiler it really does have a signficant impact on performance.
My conclusion is that TypeMock is an excellent tool for non-load test scenarios. Moq is less flexible... but much lighter weight and does not have a broad effect on general performance. With Moq you have to setup your applications specifically to be able to mock out the external dependencies (an excercise in good design anyway) but has proven to be a much better fit for my load related scenarios.
Unfortunately I did not record actual numbers in my tests regarding Moq vs TypeMock but the performance benefit of Moq is signficant in my experience.