Rhino Mocks Future
Taking Rhino Mocks to the next level?
So I've improved the interface and added constraints and callbacks, this is nice, but I think I can do more. The first issue on the table is ripping some of the innards of the library and replacing them with something saner. I'd to hack quite heavily to get it to the point it's now. Five to six levels of indirections are not fun to go through when you need to understand what is wrong. I also don't agree with some design and implementation decisions that were made. I am also quite excited about the concepts that NMock2 has to offer.
Here is what I'm envisioning:
- The explicit record / replay model is very good, and should stay as is.
- Trying to move to implicit model would mean moving to string base expectations, which is unacceptable.
- There needs to be an easier way to spesify constraints / expectations / callbacks and actions.
- Contraints - the same thing as on the NMock world.
- Expectation - what the exact method parameters are.
- Callback - calling your code when a mocked method it called.
- Actions - what to return or to throw when a mocked method is called.
- NMock2 contraints are very easy to read, and should be copied.
- Make the idea of all actions worked on last call explicit in the code. Currently this is implicit, and require deep understanding of the way Rhino Mock is implemented.
- There need to be an easy way to spesify that I'm just expecting a call, and don't care about its arguments, as this is common scenario.
Taking all of this into account, here is how I would like to have tests in Rhino Mocks:
public interface IWalker
{
void StartWalk();
void WalkFaster();
void EndWalk();
void Rest(TimeSpan howLong);
void Drink(int howManyLitters);
int CalloriesBurned { get; }
int WalkSpeed { get; set; }
}
[Test]
public void IdeadsForRhinoMocks()
{
IMock mock = new Mock(typeof(IWalker));
IWalker walker = mock.ForType(IWalker);
walker.StartWalk();
Set.Result(walker.WalkSpeed,5).Once();
walker.WalkFaster();
Set.Result(walker.WalkSpeed,7).Times(3);
Throw.On(walker.Drink(0),new NotEnoughWaterException()).Arguments(Args.IgnoreAll);
walker.Rest(new TimeSpan());
LastCall.Arguments(Is.GreaterThan(new TimeSpan(600)));
walker.WalkSpeed = 15;
LastCall.Callback = new VoidDelegate(ThrowCantWalkThatFast);
walker.EndWalk();
mock.Replay(walker);
//Or mock.ReplayAll()
ITrainer trainer = new Trainer(Behaviour.Nice);
trainer.Walk(walker);
}
What do you think of the interface?
I also want to add strict method orderring vs. relaxed method ordering. Again, NMock2 show a particular elegant way to do that.
Comments
Comment preview