我是编写单元测试的新手,所以边学边学。我正在将 Rhino Mocks 与 MsTest 框架结合使用,但有一些问题。
我在哪里可以找到一些关于 rhino mocks 的文档,概述其功能和解释,以便我可以打印出来并检查?
我见过很多关于期望的以下 2 种技术的示例,哪种技术更好或更适合特定情况?
Expect.Call( delegate { mockTestClass.MethodToMock(param) } ).Return(true);
或
var mockTestClass = MockRepository.GenerateMock<TestClass>();
mockTestClass.Expect( m => m.MethodToMock(param) ).Return( true );
接下来我想知道 stubbing 和 mocking 一个类的区别是什么,应该在什么场景下使用?
感谢您的帮助。
最佳答案
Where can I find some documentation on rhino mocks, outlining its features with explanations, so I can print off and examine?
Rhino Mocks 文档是 here一个好的 wiki 是 here .一般来说,要小心任何提及 3.3 或更低版本的内容,因为它会有些过时。
which is the better or more apt for a particular situation?
第二种方式更“流畅”,推荐。
what the difference between stubbing and mocking
这里有一些关于此的资源:
- What's the difference between a mock & stub?
- http://en.wikipedia.org/wiki/Mock_object#Mocks.2C_fakes_and_stubs
- http://codebetter.com/jameskovacs/2009/02/10/mocks-vs-stubs/
- http://martinfowler.com/articles/mocksArentStubs.html
顺便说一句,如果您刚刚开始了解这些概念,我认为您最好使用 NUnit 和 Moq。 Here's an introduction有例子。
关于c# - 关于单元测试和犀牛模拟的一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8263439/