The Artima Developer Community
Sponsored Link

Python Buzz Forum
pre-built mock classes?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Max Ischenko

Posts: 31
Nickname: maxi
Registered: Sep, 2004

Max Ischenko is a software developer from Kiev, Ukraine.
pre-built mock classes? Posted: Jun 8, 2005 9:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Max Ischenko.
Original Post: pre-built mock classes?
Feed Title: Max's blog v0.2.1
Feed URL: http://feeds.feedburner.com/MaxIBlog
Feed Description: Mastering programming and blogging
Latest Python Buzz Posts
Latest Python Buzz Posts by Max Ischenko
Latest Posts From Max's blog v0.2.1

Advertisement

There is a (relatively) widely used technique in unit testing, called mock objects. There is even a pMock library which provides a Mock class for a Python environment.

 

Given the "duck typing" nature of the Python itself, it's pretty trivial to build mocks without using any pre-built libraries. What is less trivial and potentially more worthwhile is to have a library of “stock” mock objects.

 

For instance, I found myself re-implementing ConnectionStub class again and again for different projects. And there is no shortage of other good candidates as well: socket, web request/response, thread objects, etc. Someone on a Python mailing list asks whether anyone implemented a mock filesystem interface, for example.

 

Having a library of such mock classes, realizing widely-used and “heavy” interfaces may be a good idea.

 

The only real problem I can think of is whether it’s possible to make these mocks generic enough. Mocks often contain some (application-specific) hard-coded rules and data to realize desired behavior. For instance, socket mock may fail when user attempts to write a “foobar” string – and unit test will use this to check how code handle these kind of errors. These rules may be generalized but it may lead to mock classes becoming unwieldy.

 

Even keeping this problem in mind, it’s still a reasonable idea for a library, but obviously I’m biased.

 

What do you think?

Read: pre-built mock classes?

Topic: JavaScript sucks (volume 1) Previous Topic   Next Topic Topic: Python at WWDC

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use