Meet the Author: Donald Belcham on FakeItEasyBy Paul Ballard
In the latest episode in our Meet the Author podcast series, Fritz Onion sits down with Donald Belcham to discuss his new course FakeItEasy. The interview begins with a discussion of how this course fits in with the other courses in our library on mocking frameworks and what makes FakeItEasy stand apart from the others. Donald then describes where to get the FakeItEasy framework and how to load it into your project as well as some of the constraints that are specific to writing unit tests with FakeItEasy mocks.
Listen to the Audio (MP3)
[Fritz] Hi, this is Fritz Onion. Today I’m here speaking with Donald Belcham about his new course, FakeItEasy. Donald is a Senior Software Developer, Independent Contractor, and Agile development expert, who’s a strong supporter of fundamental OO patterns and practices. He’s co-author of the book Brownfield Application Development in .NET, and actively shares his expertise with other technical professionals at user groups, code camps, and conferences held throughout the world. He’s been a Microsoft MVP in C# for — since 2007, and is a member of the JetBrains Academy. He’s also the founding member and current President of the Edmonton .NET user group. Thanks for joining me, Donald.
[Donald] Thanks for having me.
[Fritz] So this new course of yours, FakeItEasy, this is the third course on a mocking framework in the Pluralsight library. You authored one of the first two, which I believe was the MOQ course, is that right?
[Donald] Yeah, I did MOQ and Jim Cooper’s done Rhino Mocks.
[Fritz] And Rhino Mocks. So we’ve done MOQ and Rhino Mocks, and this one is another framework called FakeItEasy. And following in the pattern that we’ve kind of established for these frameworks, we get into how these integrate with unit tests, we talk about the — how to do mocking kind of by hand with hand rolling, and then get into how to use the framework effectively to simplify mocking in your unit testing in your applications. So FakeItEasy, so I think the first question that probably is coming to a lot of people’s minds is why do we have yet another mocking framework? Do you want to give a stab at that?
[Donald] So FakeItEasy looks like it was created by these guys because they didn’t like a couple of things that they were seeing in the other mocking frameworks. One of the ones is the ease of use of the interface of the mock framework itself. So FakeItEasy has a very fluent interface design to it. Everything reads like a sentence, and it should be pretty clear what you want to do when you start typing things out and seeing things pop up in Intellisense. The other reason is that the other mocking frameworks have always included a concept of mock objects being separate from stubs. So mock objects are the objects you use to verify interaction between the system under test, and the dependency that is being called by that system under test, stubs are objects that you use to return specific values back from those dependencies, so that you can control the execution flow inside the system under test. And they didn’t like that idea, it was too confusing for a lot of developers. So they said let’s just have a fake object, and FakeItEasy is then as a framework going to decide should this fake object act like a stub object, or should it act like a mock object? And it does that all at run time, so you as a developer don’t have to think of it.
[Fritz] Interesting. So aesthetics was certainly one part of it, that they have a nice fluent interface that reads well as you’re writing your tests, and then the other aspect is this understanding the difference between a mock and a stub, and their point is you really shouldn’t even have to think about that as a developer. Does that kind of sum it up?
[Donald] Yeah, that’s basically it. You know, make it as easy as possible for a new developer to mocking style tests to take on the framework and get some tests written.
[Fritz] Huh, it does sound appealing. So just out of curiosity, is this your personal favorite framework? Is that — does that work for you, having the nice fluent style interface and the not having to distinguish between mocks and stubs?
[Donald] Yeah, there’s definitely a benefit there. And it’s something that when I’m going into client sites and they’ve never done fake or mocking object type situations before, it makes for a great introduction level. And for the vast majority of what people need to do in testing, it’s going to cover everything they have. So yeah, it’s a great place for you to start, and the fluent interface makes creating everything in your code so easy that — that yeah, I would say it’s on my list of ones that I would use all the time.
[Fritz] Great. Okay, well let’s talk a little bit about bringing this into your project. So I assume it’s like many of the other mocking frameworks, that you can download it either with NuGet, or from the GitHub site, and bring it into your application, and then just start using it. Is there anything special about FakeItEasy relative to that?
[Donald] No, it’s like most other mocking frameworks, that, you know, FakeItEasy you grab it off a NuGet, or I guess you could download the source and compile it from GitHub. And then you just need to work and write tests like you would with MOQU or RhinoMocks. You need to be doing some kind of dependency injection in your code so that you can pass in the fake objects to it. It’s not going to be like type moq or mocks from Visual Studio 2012, which can be very invasive and get into tightly coupled code and fake out the objects in it. It does require you to follow DI patterns to be able to make good use of it.
[Fritz] DI being dependency injection.
[Donald] Yeah, dependency injection.
[Fritz] Okay. So in that sense this is a very pluggable framework? You can swap it in — well I guess you couldn’t swap it out because of the syntax, but the integration is through dependency injection?
[Donald] Yeah, the integration point to your system under test is going to be through integration. So if you are using something else, and you’re not happy with it, you don’t have to change the system under test to start using FakeItEasy. You just can take out the existing framework you’re using, and write tests that make use of FakeItEasy, and call the system under test the same way.
[Fritz] I see. Great, well it sounds like we need to schedule yet another course to get into the Visual Studio 2012 mocking system now too, don’t we?
[Donald] Yeah, I think Visual Studio 2012 mocks would pretty much complete the mocking framework course library that is on Pluralsight at this point.
[Fritz] Sounds like an opportunity knocking.
[Donald] Yes, it is.
[Fritz] Alright. Well, this is Donald Belcham with his new course FakeItEasy, a new and simpler mocking framework. Thanks very much, Donald.
[Donald] Thank you.
About the Author
Paul Ballard is a Chief Architect specializing in large scale distributed system development and enterprise software processes. Paul has more than twenty years of development experience including being a former Microsoft MVP, a speaker at technical conferences such as Microsoft Tech-Ed and VSLive, and a published author. Prior to working on the Windows platform, he built software using a vast array of technologies including Java, Unix, C, and even OS/2.
- Meet the Author: Donald Belcham on Mocking with Moq
- New course: FakeItEasy
- Meet the Author: Donald Belcham on PostSharp Fundamentals
- Meet the Author: Jim Cooper on Rhino Mocks Fundamentals
- Meet the Author: Donald Belcham on Brownfield Application Development
- Video: Fake it Until You Make It with FakeItEasy
- New course: Mocking with Moq
- Meet the Author: John Sonmez on Enterprise Library Data Access Application Block
- Meet the Author: Oliver Sturm on Introduction to F#
- Meet the Author: John Sonmez on Enterprise Library Caching Application Block