O'Reilly logo

Professional Test-Driven Development with C#: Developing Real World Applications with TDD by Jeff McWherter, James Bender

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MOCKING FRAMEWORKS

Chapter 2 discussed the basics of mocking objects, and throughout this book we have been using the Moq framework because of its simple syntax. Moq is becoming a popular mocking framework, but it is not the only framework available. Other frameworks have features that allow you to mock objects differently.

Moq uses a declarative syntax for mocking objects, which is different from the record/playback method of mocking that many mocking frameworks support. Many of these frameworks are moving away from the record/playback method in favor of an arrange, act, and assert (AAA) method because of its ease of use.

Rhino Mocks

Rhino Mocks is a free mocking framework created by Orin Eini, who is also known for his work on the nHibernate and Castle projects. Rhino Mocks is popular because of its ease of use and list of power features. Although the syntax is not as clean as Moq's, it is a worthwhile tool to check out. Rhino Mocks supports two different styles of mocking objects: the record/playback method and the arrange, act, and assert syntax. Record/playback is now considered to be the older way of mocking objects, but it makes sense to consider the differences.

The following example uses the AAA style of mocking objects, which is similar to mocking with Moq, as you learned in Chapter 2. The basic Rhino Mocks syntax looks like this:

images
MockRepository mocks = new MockRepository(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required