5.2. Dynamically creating a fake object

Let’s define dynamic fake objects and how they’re different from regular, handwritten fakes.


A dynamic fake object is any stub or mock that’s created at runtime without needing to use a handwritten (hardcoded) implementation of that object.

Using dynamic fakes removes the need to hand-code classes that implement interfaces or derive from other classes, because the needed classes can be generated for the developer at runtime, in memory, and with a few simple lines of code.

Next, we’ll look at NSubstitute and see how it can help you overcome some of the problems just discussed.

5.2.1. Introducing NSubstitute into your tests

In this chapter, I’ll use NSubstitute (http://nsubstitute.github.com/ ...

Get The Art of Unit Testing, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.