Wednesday, July 29, 2009

Introducing Legend.Fakes

OK, you’ll think I’ve lost it – or maybe you never thought I had it – but I’m creating my own mocking framework.

Why? Well, first of all because I wanted a framework that is more semantically correct and easier to understand so instead of distinguishing between mocks and stubs it just produces “fakes”, if a fake is a mock or a stub depends on the use of it. I also wanted a simpler and cleaner syntax for configuration, I’m really not a fan of the many extension methods cluttering Intellisense in your tests when using Rhino Mocks (although I really love Rhino Mocks).


I also thought it would be a really nice learning experience. Finally there are a few features I think will be cool that I will include that no other framework has (to my knowledge, though I’m only really familiar with Rhino).

But the main feature is and should be ease of use, so, to create a fake object (whether it’s a mock or a stub) you’d write this:

IFoo foo = A.Fake<IFoo>();

I’ll write more about other features, my learning experience while implementing this and post code soon.


  1. Have you ever looked at Moq? ;-)

  2. I have looked at it yes, not very much though. It seems to have a lot of the features I want, but I don't like the model of a mock object that isn't the fake itself.

    In moq:
    var mock = new Mock{IFoo}();
    IFoo foo = mock.Object;

    In FakeItEasy:
    var foo = A.Fake{IFoo}();

    This is not something huge ofcourse.

    But then as I write, the main reason for me to do this is as a learning experience, I want a "playground" for trying out new features for mock frameworks, if I come up with something good, who knows, maybe I'll get a chance to contribute to Moq.

    FakeItEasy supports way better than Rhino.Mocks, I'm not sure how support is for VB in Moq.

    I also wanted the avoid the words "Mock" or "Stub" anywhere in the framework.

    Another thing I've done is to remove expectations all together.

    Extensibility is a huge thing. You can create your own ArgumentValidations in my framework and since the Argument.Is-property can be extended with extension methods your custom validations look no different to the framework validations.

    I quite like the wrapping feature I blogged about, I haven't found that in any other framework.

    There are other features coming up that I haven't seen anywhere else as well.

    All that being said, I'd encourage anyone to use Rhino.Mocks or Moq, I would encourage no one to use FakeItEasy as it is right now, it's in alpha and I think it will stay in alpha for quite some while.