Unity Nunit &犀牛模拟
任何人都可以给我一个很好的例子,如何将 rhino mocks、nunit 和 unity 一起使用。我正在阅读每个项目的帮助,但似乎没有任何好的示例项目来说明如何一起使用它们以及使用它们设置项目/测试项目的方法。即,您是否在测试项目中创建指向虚拟类的新 ioc 容器。那么犀牛又从何而来呢?
感谢您的任何帮助。
could anyone give me a good example of using rhino mocks, nunit, and unity together. I am reading the help on each but there doesnt seem to be any good sample projects of how you would use them together and the way to set up projects /test projects using them. I.e. do you create new ioc containers in your test project which point to dummy classes. Then where does rhino come into it.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同时使用这 3 个框架。看起来你的问题是你试图同时学习太多东西。
至于在测试中使用 IoC 容器,我从来不需要在单元测试中这样做 - 我只是根据需要使用 Rhino 模拟来传递依赖组件的存根/模拟。
对于集成测试,我可以看到在某些代码中初始化 IOC 容器的好处,例如,如果您使用 MVP 模式并希望用存根完全替换 GUI。
我首先会更详细地了解单元测试。我强烈推荐这本书单元测试的艺术。我发现一本结合了 IOC、单元测试和隔离框架的好书是 Pro ASP.NET MVC< /a>- 现在有第二版,但因为我还没有读过,我实在无法评论。本书不使用 Unity,但如果您了解一种框架的工作原理,就可以轻松切换到使用另一种框架。当我从 Moq 迁移到 Rhino 时,我发现这个 wiki 页面特别有用 。
I use all 3 of these frameworks together. It looks like your problem is you are trying to learn too many things at once.
As for using an IoC container in tests, I've never had the need to do this for unit tests- I just use Rhino mocks to pass in stubs/mocks for dependent components as required.
For an integration test I could see the benefit of having an IOC container initialised in some code, for example if you were using the MVP pattern and wanted to completely replace a GUI with stubs.
I would first learn about Unit testing in more detail. I highly recommend the book The Art of Unit Testing. A good book that combines IOC, Unit testing and an isolation framework, I found was Pro ASP.NET MVC- there is now a 2nd edition, but as I've not read it, I can't really comment on it. The book doesn't use Unity, but if you learn how one framework works, it is easy to switch to using another. When I moved from Moq to Rhino, I found this wiki page particularly useful.
您不需要在单元测试中使用 IoC。您应该测试接口的实现,而不是接口本身。
示例:Person 实现 IPerson。您应该有一个测试 Person 的 PersonTests 类。您使用Rhino Mocks 创建IPerson 的模拟或存根并测试Person 类的功能。
(至少,我总是这样做)。
然后,您可以进行单独的测试来测试您的 IoC(如果需要)。
You don't need to use IoC in your unit tests. You should be testing the implementations of the interfaces and not the interfaces themselves.
Example: Person implements IPerson. You should have a PersonTests class that tests Person. You use Rhino Mocks to create a mock or stub of IPerson and test the functionality of the Person class.
(At least, that is the way I always do it).
You then have separate tests to test your IoC (if you need to).