>From memory I think the main difference is that GenerateStub<T>
returns an object with normal property behaviour.

For example (psuedo-code only, haven't tested):

var stub = MockRepository.GenerateStub<ISomething>();
stub.MyProperty = 2;
Assert.AreEqual(stub.MyProperty, 2);

If you try the same with a mock then MyProperty would return 0 (or
null for reference type). If you want the property of a mock to return
a specific value you have to stub it (confusing, right? :-)).

var mock = MockRepository.GenerateMock<ISomething>();
mock.MyProperty = 2;
Assert.AreEqual(mock.MyProperty, 0);
mock.Stub(x => x.MyProperty).Return(2);
Assert.AreEqual(mock.MyProperty, 2);

I think that's right, but you should probably run it and make sure I
have a vague idea of what I'm talking about. ;)

My approach is to use GenerateStub<T> everywhere. I don't remember the
last time I needed/wanted the GenerateMock<T> behaviour (at least not
when using AAA style testing).

Hope this helps.
Regards,
David

On Fri, Nov 27, 2009 at 7:53 AM, changhong <[email protected]> wrote:
> I use AAA syntax, and I couldn't find any difference between objects
> created by MockRepository.GenerateMock<T> or
> MockRepository.GenerateStub<T>.
>
> I noticed with both objects, you can setup stubs or expectations using
> obj.Stub(..) or obj.Expect(...), for both objects, test won't fail if
> an expectation does not happen. Also with both objects, you can verify
> an expectation using obj.AssertWasCalled(...), and they behave the
> same.
>
> Can anyone tell me what the difference between those two? And how
> should I choose one over another?
>
> Manny Thanks.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rhinomocks?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en.


Reply via email to