HTML and CSS Reference
In-Depth Information
16
Mocking and Stubbing
W hile using test-driven development to develop five sample projects, we've
become intimately familiar with the stubFn function. We have used it as a tool to
both inspect interaction between objects, as well as isolating interfaces under test.
But what exactly is a stub? We are about to find out as we dive a little deeper into
the topic of using test doubles, objects that look like the real thing but really are
bleak impersonations used to simplify tests.
In this chapter we will look at the general theory of using test doubles, and
get to know a few common types of test doubles a little better. Because we have
already used stubs extensively in tests throughout Part III, Real-World Test-Driven
Development in JavaScript, we will relate the discussion to previous examples. We
will also look at a more capable stubbing and mocking library and see how such a
thing can be used in place of stubFn and other homegrown helpers to simplify
some of the tests we have written so far.
16.1 An Overview of Test Doubles
A test double is an object that supports the same API, or at least the parts of it
relevant to a given test, as the real thing, but does not necessarily behave the same
way. Test doubles are used to both isolate interfaces and make tests more convenient;
making tests faster, avoiding calls to inconvenient methods, or spying on method
calls in place of assertions on direct or indirect output.
439
 
 
 
Search WWH ::




Custom Search