SilverMock : Open Source Mock library for Python

Posted on December 19th, 2007 in Agile, Mocks, Tool by siddharta || 1 Comment

A new release! SilverMock is a python mock object library that was developed for internal use at Silver Stripe Software. It is now being released under the MIT License. If you are looking for a simple, lightweight mock object library for Python, then check out SilverMock.

I first did a demo of SilverMock during the 2nd Chennai Agile User Group meet earlier this month to demonstrate writing unit tests with mock objects. In the discussion, we though it might be useful to create a screencast of the demo. While preparing the screencast, I though why not release SilverMock under an open source license? So thats where we are now.

If you go to the SilverMock page, you’ll find the first part of the screencast showing how you can use mock objects during unit tests. Since the screencast uses SilverMock, it doubles up as a bit of documentation as well :)

The idea behind SilverMock is to make mock objects as simple as possible. The whole library is under 200 lines of python code (under 400 is you include the unit tests), so it’s very lightweight. The API is as straighforward and readable as it gets. IMHO, you read a line like ShouldBeCalled(“count”).with_args((“abcd”,)).and_return(4) and you immediately know what is expected to happen. If you find all this intriguing, then head over to the SilverMock page, where you can download SilverMock, check out the screencast and see an example of a typical unit test that uses SilverMock. Hope you find it useful!