tags:

views:

209

answers:

5

Following on from my last question "What is a "Stub", I would really like to sit down tonight and play more with creating stub objects.

What is your tool of choice for creating Stub objects?

And for bonus points :)

Can you also link to any good tutorials for getting started with them?

Thanks a lot guys and girls, appreciated :)

FYI - I am using .NET (2.0 @ Work, 3.5 @ Home)

+4  A: 

Simply, Rhino.Mocks. Yes, "Mocks Aren't Stubs", but Rhino.Mocks does both. Before wrapping my brain around Rhino.Mocks I hand-coded my own stubs. Never again.

Sorry, I don't get the bonus points. Ayende.com, the place to get Rhino.Mocks, has decent online documentation, and a forum full of questions. The author is actually very good at responding and answering too. I don't feel like there's a good "shortcut" to learning how to use it; for this I think it's through practice and/or trial-and-error that it's best learned.

(In rereading the above, I don't mean it to sound like RTFM even though it may come across that way.)

JMD
Funny you say that, I have been getting in to Rhino Mocks (for Mocking) and noticed it had a Stub<T> method, so have been researching that as well. Would be good to have a one-stop shop.. With regards to the bonus points.. How about any anecdotes to share if you use it yourself? :) Thanks for answer
Rob Cooper
I can't recall any good anecdotes specifically. All I can really say is that Rhino.Mocks frustrated the bejeezus out of me for a good two weeks before I had my Ah-hah!-moment. I was so used to manually coding my stubs (to test values) that it took a while to get used to testing behaviour instead.
JMD
Well, it was nice to read that I am not alone here! I am finding it.. Challenging.. I spent three hours last night pretty much writing nothing! :) Thanks again :)
Rob Cooper
PS: I never took it as "RTFM" - but thanks for clarifying :)
Rob Cooper
Here is the link http://ayende.com/projects/rhino-mocks.aspx
epotter
+1  A: 

I have used Rhinomocks for some time now. The problem with it is that it allows all kinds different of strategies and syntaxes for creating mocks and stubs. The object model is getting kind of crowded with all kinds of extension methods, functions and objects that are only useful in certain contexts. This makes it harder to learn.

I'm a fan of the AAA syntax so I'll probably switch to Moq for my next project, it's a bit newer than rhino mocks. It has stolen a couple of good ideas from rhino mocks but has none of the old cruft that rhinomocks has collected over the years. If you're new to mocking and stubbing I'd certainly look into it.

Mendelt
Thanks Mendelt. Been checking out the AAA syntax (really need to get used to Lambdas!) http://bit.ly/U3Yk - Also checked out Moq, looks good, but has the dependency for 3.5 - May make work adoption hard http://bit.ly/13FYvA - Thanks for the answer!
Rob Cooper
+1  A: 

Following on from my comment on JMD's Answer..

I have been checking out Rhino Mocks, I have heard before that it also has stub functionality, so it would make sense to check out how that works.

I have not had a chance to produce much code with these, but here are some useful links I have found (thus far):

Rob Cooper
+1  A: 

RhinoMocks is great and very complete, but I found moq was much simpler to learn and use.

var mock = new Mock<IFoo>();
mock.Expect(foo => foo.Execute("ping")).Returns(true);

I also use RhinoMocks, and it's great, but I guess I find moq's API very discoverable, and the (short) documentation very helpful. Even Phil Haack wasn't aware of all of RhinoMocks' capabilities when he compared it to Moq, which is a statement about discoverability.

orip
Agreed, I like the rhino mocks AAA syntax a bit better than the Moq systax (it's largely inspired by Moq though) but the fact that Moq doesnt have all the legacy baggage makes it much more discoverable.
Mendelt
A: 

We've developed a stub framework for Pex that you can read (and learn) about at http://research.microsoft.com/stubs. This framework is different in many ways from Rhino/Moq: it's 'just' for stubs and source code generated.

Peli