Unit testing in Extreme Programming
Introduction to paper on Unit Testing with Mock Objects
Unit testing is a fundamental practice in Extreme Programming [Beck 1999], but most nontrivial code is difficult to test in isolation. You need to make sure that you test one feature at a time, and you want to be notified as soon as any problem occurs. Normal unit testing is hard because you are trying to test the code from outside. We propose a technique called Mock Objects in which we replace domain code with dummy implementations that emulate real code.
These Mock Objects are passed to the target domain code which they test from inside, hence the term Endo-Testing. This practice is similar to writing code stubs with two interesting differences: we test at a finer level of granularity than is usual, and we use our tests and stubs to drive the development of our production code.
Our experience is that developing unit tests with Mock Objects leads to stronger tests and to better structure of both domain and test code. Unit tests written with Mock Objects have a regular format that gives the development team a common vocabulary. We believe that code should be written to make it easy to test, and have found that Mock Objects is a good technique to achieve this. We have also found that refactoring Mock Objects drives down the cost of writing stub code. In this paper, we first describe how Mock Objects are used for unit testing. Then we describe the benefits and costs of Mock Objects when writing unit tests and code. Finally we describe a brief pattern for using Mock Objects.
on July 4, 2009 on 5:53 am
[...] Unit testing in Extreme Programming [...]