Ayende @ Wiki

Partial mocks are useful when you want to mock a part of a class. This allows you to test abstract methods in isolation, for instance.

Let's imagine this (useless) class. We want to test that the Inc() method is doing its job, but we don't want to implement a derived class yet.
public abstract class ProcessorBase 
{   
  public int Register;
  public virtual int Inc()
  {
    Register = Add(1);     
    return Register;
  } 
  public abstract int Add(int i); 
}
Here is what we need to do:
[Test]
public void UsingPartialMocks()
{
  MockRepository mocks = new MockRepository();
  ProcessorBase proc = (ProcessorBase) mocks.PartialMock(typeof (ProcessorBase));
  Expect.Call(proc.Add(1)).Return(1);
  Expect.Call(proc.Add(1)).Return(2);
  mocks.ReplayAll();
  proc.Inc();
  Assert.AreEqual(1, proc.Register);
  proc.Inc();
  Assert.AreEqual(2, proc.Register);
  mocks.VerifyAll();
}
And with generics:
[Test]
public void UsingPartialMocks()
{
  MockRepository mocks = new MockRepository();
  ProcessorBase proc =  mocks.PartialMock<ProcessorBase>();
  Expect.Call(proc.Add(1)).Return(1);
  Expect.Call(proc.Add(1)).Return(2);
  mocks.ReplayAll();
  proc.Inc();
  Assert.AreEqual(1, proc.Register);
  proc.Inc();
  Assert.AreEqual(2, proc.Register);
  mocks.VerifyAll();
}
This is a contrived example, but you can see how we can use this feature to test Template Methods and abstract classes easily. A partial mock will call the method defined on the class unless you define an expectation for that method. If you have defined an expectation, it will use the normal rules for this. (Be aware, though, that once all the expectations for a method are settled, the method will be routed back to the implementation.)

Up: Rhino Mocks Documentation
Next: Rhino Mocks - Stubs

ScrewTurn Wiki version 2.0 Beta. Some of the icons created by FamFamFam.