问题
This question clarifies the conceptual differences between mocks and stubs in Rhino: What are the differences between mocks and stubs on Rhino Mocks?
However I'm left confused why Rhino Stub objects provide methods such as .Expect
and .VerifyAllExpectations()
when these appear to do nothing at all. Why do mock/stub objects seemingly provide the same interface?
It's making me think I've missed something fundamental - or is it just an implementation quirk?
回答1:
The reason for this behavior is based on IntelliSense limitation(on extension methods) + Rhinomocks design( + bug on the asserts) as I explained here.
The following example shows that the Expect
method has nothing more than Stub
method on stubs.
public class Foo
{
public virtual string DoSomthing()
{
return String.Empty;
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var f = MockRepository.GenerateStub<Foo>();
f.Expect(x => x.DoSomthing())
.Return("2");
f.VerifyAllExpectations();
}
}
If you'll execute the above example you'll see that the test won't fail(Although DoSomthing
was never called...)
来源:https://stackoverflow.com/questions/37305338/why-do-rhino-stubs-allow-me-to-set-expectations-on-them