Mocking .NET Without Hurting Its Feelings

By John M. Wright

Elevator Pitch

Learn about the two types of mocking frameworks: constrained (RhinoMocks) and unconstrained (Typemock Isolator). Dig into how they do their magic and discuss their pros, cons, and limits. Look at examples of how to use the frameworks, mocking out dependencies from code and third-party logic.

Description

Unit testing has become an accepted part of our lives as .NET programmers. To help focus our tests to only the code we want to validate, Mocking Frameworks are a powerful tool in our toolbox. Like many tools, if you have an understanding of how the tool works under the hood, you can bend it to your will (and also know where it’ll break if you bend too much).

In this session, you’ll learn about the two main types of mocking frameworks: constrained frameworks (like RhinoMocks and Moq) and unconstrained frameworks (such as Typemock Isolator and Telerik JustMock). I’ll dig into how the two actually do their magic and we’ll discuss the pros, cons, and limits of both. We’ll look at examples of how to use the frameworks in your tests, mocking out dependencies from your own code and even third-party logic.

You’ll get the most out of this session if you’re comfortable reading C# code and have a general understanding of class inheritance in .NET, along with some experience writing and running unit tests. Prior experience using mocking frameworks is not necessary.

Notes

For over a decade, I’ve been a big fan of TDD in .NET and the technologies that make it easier. I’ve written several blog posts on mocking frameworks, from “Quick Guides” for RhinoMocks, Moq and NSubstitue, to deeper on how the various mocking frameworks actually work at runtime and how to use the Reflection APIs to mock/test non-public members. I gave this talk at Chicago Code Camp 2017 to a packed room and would love to do it again for you! You can see the blog posts, slides and more at https://wrightfully.com/mocktalk.