London software testing news UK


Unit testing in Extreme Programming

Posted in Software testing by testing in London on July 21, 2007

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.

Agile software testing

One Response to 'Unit testing in Extreme Programming'

Subscribe to comments with RSS or TrackBack to 'Unit testing in Extreme Programming'.

  1. A really good Spring book from Packt! “Spring Web Flow 2 Web Development” – Lijin’s Localhost said,

    […] Unit testing in Extreme Programming […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: