Hibernating Rhinos - Episode #1: Rhino Mocks 101

To celebrate the Rhino Mocks 3.0 release, I produced a screen cast of about an hour, talking about how you can use it. This is the very first time that I am doing something like this, so the list of fubars in this episode is fairly long. For instance, I didn't realize that the Play/Pause bar would appear in the final movie, or thought about closing the IM during recording, etc.

At any rate, I think that this could provide a gentle introuction to Rhino Mocks, and help understand how to use it. The first few minutes are introductions and power point, but from then on, it is all code, so have fun.

You can watch it here.

Oh, and happy mocking.

Print | posted on Wednesday, March 28, 2007 11:22 PM

Feedback


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/28/2007 11:42 PM cristian

Would you mind checking the download? It doesn't seem to work.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/28/2007 11:46 PM Adam

Same for me...


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/28/2007 11:50 PM Leo

Wow atleast hide the detailed error page !!


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 12:02 AM Ayende Rahien

Please try now, it works.
@Leo, sorry about the error, I turned detailed errors on so I could figure out issues with the site.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 1:53 AM Adam Tybor

Very nice! I can't wait to see more.

If you continue to do these one suggestion would be to try and include, like you did with Do() and LastCall.Constraints, practical examples of how to take advantage of all magic in RhinoMocks.

As always, nice work.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 2:50 AM Chris Vickerson

I do appologize in advance if this information is in this first webcast - I'll watch it later tonight. I've been contemplating using RhinoMocks for quite some time - to finally learn how to incorporate mocking into our process of developing. When I approach others I work with I always get hammered with reasons not to use mock objects. One that keeps coming up is how to mock frameworks such as Windows Workflow Foundation. Would you consider covering the topic of mocking large existing frameworks (eg. ASP .Net or WWF)?


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 8:14 AM ralf

Your download is broken.
Exception Details: NHibernate.QueryException: in expected: f [from Feed f where f.Section.Id = :sectionId]


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 8:31 AM Ayende Rahien

@Chris,
I did some work a while ago about mocking WCF, you can search the blog on that
ASP.Net itself is not mockable/testable easily, and that is a big draw back as far as I am concerned.
I am talking about it in the screencast, but in general it is a bad thing to mock stuff that you don't controol/own.
The reason is that you usually does a lot of low granularity work with it, which is a PITA to mock.
Adapters are usually the answer for this case.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 8:36 AM Ayende Rahien

@Ralf,
Please try now, it is working.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 4:43 PM Joe

You mention early on that you consider testing webservices / database calls to be integration testing. A lot of what I (and I would imagine pleanty of other people) do centers around getting the stored procs / views set up and ensuring that the right data is being returned, and for those of us not using any kind of OR/M, ensuring that we can do the CRUD from our applications. What would be your suggestion on how to approach this?


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 4:56 PM Liang

Which tool we should use to view? I only can hear... Thanks!


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 6:15 PM Ralf

Download works like a charm, screencast is really good. Maybe the next time you should post at what time in the screencast you start coding, so I can jump just there ;-)
One thing I noticed: You always go back to the unit test code after you have changed something and have to run the test again. Are you doing that intentionally for the sake of the screencast or are you unware of Testdrivens "Repeat Test Run" command. I know it took me a couple of month until I discovered it. Know I have a keyboard shortcut for it


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/29/2007 7:11 PM Ayende Rahien

@Liang,
You need to install the TSCC plugin (you can find the download link at the download page) and watch it in Windows Media Player


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/30/2007 1:58 AM Doug Rohm

I can't get it to download either. The links in the post go to the same page.. I also have the plugin installed so it can't be that...

Doug


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/30/2007 7:41 AM Adam Tybor

@Joe
Checkout Rhino Commons, it has some nice text fixture stubs in ForTesting that allows you to use SqlCe and SqlLite to do quick "integration testing".

While CRUD testing is important the ORM handles this for you. The only persistence stuff I test is ensuring things like lazy loading and cascades are being handled properly. SqlCe works perfect for that. For the heavier integration tests we let our CI server handle that. Rarely do we find that integration tests fail if all unit tests are passing.

Adam


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/30/2007 11:06 AM Ayende Rahien

What do you mean, you can't download it?
The link in the post goes to the download page, and the link to actually download the link to actually download the file is in the bottom of the screen.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/30/2007 1:16 PM Gulli

The confusion is about the text "You can watch it here" where "here" is a link.

Naturally, we click "here", but that's just a link to the same page. :)


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/30/2007 1:52 PM Ayende Rahien

Oh, that is just the post text, actually. sorry about being confusing


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 3/30/2007 6:10 PM Robert Taylor

I really like the video - you did an excelent job of showing how to use RhinoMocks in a (near) real-world scenario. You mentioned how it is common for developers to forget to call ReplayAll() and i think i have a solution to that problem: take advantage of the "using" statement in the language by implementing a couple of new APIs and IDisposable...

using System;
using MbUnit.Framework;
using Rhino.Mocks.Constraints;

namespace Rhino.Mocks.Demo
{
[TestFixture]
public class RhinoMocks101Fixture
{
private MockRepository mockRepository;
private ISmsSender smsSender;
private IUserRepository userRepository;
private User user;
private LoginController loginController;

[SetUp]
public void TestInitialize()
{
mockRepository = new MockRepository();
smsSender = mockRepository.CreateMock<ISmsSender>();
userRepository = mockRepository.CreateMock<IUserRepository>();
user = CreateUser();

loginController = new LoginController(smsSender, this.userRepository);
}

[Test]
public void WillSendSMSWhenUserRequestNewPassword()
{
//nested scopes are not allowed; exception will be thrown
//calling any mocked API outside of a scope will throw an exception
using (this.mockRepository.RecordScope())
{
Expect.Call(this.userRepository.GetById("sally")).Return(this.user);
smsSender.SendSms(null, null);
LastCall.Constraints(Is.Equal(this.user.Phone), Text.StartsWith("New passord:"));
}

using (this.mockRepository.PlaybackScope())
{
loginController.SendNewPassword(this.user.Name);
} //disposing of the PlaybackScope will call VerifyAll()

Assert.AreNotEqual("old", this.user.Password, "expected the password to change");
}
}
}


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 4/3/2007 9:13 AM Kirill

Great screencast! Btw, what font do you use in visual studio?


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 4/3/2007 1:27 PM Ayende Rahien

Thanks, and it is consolas.


Gravatar

# An Introduction to Mocking 4/3/2007 7:01 PM Christopher Bennage

Ayende has published an excellent sceencast introduction to Rhino Mocks . If you are at least somewhat


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 4/4/2007 7:33 AM Ayende Rahien

I am aware of the Repeat Test Run, but I keep forgetting about it.
It is great when I am in the code, and I can just run the test again and again until I get it right.
In fact, if I am not mistaken, this is there because of a feature requst I made.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 4/4/2007 7:35 AM Ayende Rahien

@Robert,
Rhino Mocks had using() scope for verification at the beginning, but it was removed because people kept running into issues with it.
The most common issue was that if an exception was thrown when the mocks was in an invalid state, the using's dispose kicked in, attempted to verify, failed, and then threw a _different_ exception, masking the real issue.


Gravatar

# re: Hibernating Rhinos - Episode #1: Rhino Mocks 101 5/14/2007 4:03 AM jdn

http://www.blogcoward.com/archive/2007/05/13/15.aspx

Comments have been closed on this topic.