Question

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)

Was it helpful?

Solution

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.)

OTHER TIPS

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.

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):

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top