I don't actually care about 'interaction based' or 'state-based'
definitions. Because you mostly don't have a choice. You have to test
what your unit under test is responsible for. If you want to test that
a service has been called, you need a mock with an expectation. If you
want to test the result of a calculation, you need to get this result.
Is it returned, it is easy. Is it only passed to another class, you
need a mock. Does the unit under test call services where you don't
care for a certain test, you can use a stub. And so on. You mostly
can't choose. If you can, you should ask yourself: which is the most
stable and secure and also easiest way to test it? To only test what's
important? However-based you'll call it.
Back to the topic: What is the difference in Rhino Mocks? Not in the
theory, we might all differ in our theories, guidelines and points of
view. If nobody actually knows the difference I'll read the code or
write some tests to find out. Actually, I don't have the time to do
this, but one day I have to know it well.
As a guess, it will be something like "Strict mocks only do what you
specify. Dynamic mocks accept calls that are not specified and (guess)
return default values. Stubs additionally have property behavior
defined for all properties" or something like this. If that's really
everything, then there isn't a big difference. You'll say: Do I want
do define PropertyBehavior() on all properties or just take a stub? Do
I want to define Repeat.Any or Repeat.Once on all methods or just take
dynamic mock or strict mock respectively? So it's just a matter of
writing less code.
On 10 Nov., 00:42, "Tim Barcz" <
timba...@gmail.com> wrote:
> So the problem that I have with this is that you're really teaching them the
> wrong thing (using mocks) and they will later have to course correct.
>
> Since my talk was yesterday, and it went very well, here are the guidelines
> I gave:
>
> - Favor GenerateStub over GenerateMock
> - Favor state-based testing
> - Use interaction based to test void method
>
> After talking to some new mock users the usage of stubs were easier for them
> (since you can treat just like a normal object with getters and setters).
>
> These guidelines are not my own but adopted from others out there. I also
> feel it sets up beginners for less relearning later on.
>
> Tim
>