Code Jam: Automated Unit tests with Mocks and Stubs 1

Posted by Conrad Benham on October 02, 2008

According to Wikipedia “…unit testing is a method of testing that verifies the individual units of source code are working properly. A unit is the smallest testable part of an application.” Doing this can be difficult when we are unit testing code on boundaries. A naive attempt to unit test a system boundary such as a database would actually mean communicating with a live database directly. This means the database must exist, all tables created and all data must be in a known state prior to the test commencing. Once the test is complete (with a success or failure) the database must then be returned to it’s original known good state. Not only is building the infrastructure required to do this potentially time consuming, so too is the actual execution of such a test. Further, such testing is really no longer a unit test but an integration test, it certainly defeats the goals as stated in the above mentioned extract.

Enter mocks and stubs. In this Code Jam we’ll look at some techniques we can apply to reduce our reliance on external systems. This will be through the application of mocks and stubs. We’ll identify the differences between the two approaches and when one should be used over the other. We’ll also look at a variety of open source mocking frameworks. If time permits we’ll also look at how mocking helps layer an application to aid in low coupling and high cohesion (Vidor Hokstad has written a nice blog entry on this).

So, come along and learn some of the concepts of mocking. While this code jam is aimed at developers anyone who is interested should come along. While it is not necessary, as we tend to pair in these sessions, it would be helpful if you could bring a laptop along if you have access to one. If you don’t have a laptop don’t let that stop you from coming along.

When: 7:30pm, Thursday 9th of October 2008
Where: ThoughtWorks Hong Kong Office
Address: Room 1304, 13/F, Tai Tung Building, 8 Fleming Road, Wanchai
Map: ThoughtWorks Hong Kong
Contact

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. […] is my second times go agile Hong Kong event, I go because I want to increase my testing […]

Comments