Chapter 5. Isolation (mock object) frameworks
This chapter covers
- Understanding isolation frameworks
- Defining fake objects
- Using Rhino Mocks to create stubs and mocks
- Surveying advanced use cases for mocks and stubs
- Exploring arrange-act-assert and record-and-replay syntax
- Avoiding common misuses of isolation frameworks
In the previous chapter, we looked at writing mocks and stubs manually and saw the challenges involved. In this chapter, we’ll look at some elegant solutions for these problems in the form of a mock object framework—a reusable library that can create and configure stub and mock objects at runtime. These objects are usually referred to as dynamic stubs and dynamic mocks.
We’ll start this chapter off with an overview of mock object frameworks (or isolation frameworks—the word mock is too overloaded already) and what they can do for us. We’ll then take a closer look at one specific framework: Rhino Mocks. We’ll see how we can use it to test various things and to create stubs, mocks, and other interesting things.
Later in this chapter, we’ll contrast Rhino Mocks with other frameworks currently available to .NET developers, and we’ll finish with a list of things to watch out for when using such frameworks in your tests.
Let’s start at the beginning: What are isolation frameworks?
We’ll start with a basic definition.