Talk:Mock object

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computer science (Rated Start-class)
WikiProject icon This article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 

Merge this[edit]

Mock objects are used in TestDrivenDesign (TDD). A class may interact with various neighbouring objects. When writing a unit test for the primary class, neighbouring classes are replaced with mock objects. In the test, these behave just like real objects. The programmer will set up return values for mock object methods as well as expectations for the number of times each method is called. Expected arguments for each mock method call can also be defined.

In this way, the primary class can be tested without the secondary, neighbouring objects having to exist at all. This allows testing to be used as a design tool: you can start at the top and watch the design riple out as you work your way down. Once a primary object and its test has been written, the mocks (and further unit tests) are implemented.

Rework[edit]

I hope I managed to make this article more accessible to laypeople; in particular, I felt that the e-mail client example was too technical for this article. I realize most of us Wikipedia geeks are, well, geeks, but really, this isn't Slashdot. Ataru 18:51, 28 June 2006 (UTC)

I agree; your alarm clock example is much better. --Babomb 06:04, 29 June 2006 (UTC)

Stub vs Mock[edit]

Would a reference to the fact that many people would still use the term "stub" make everything clearer. A stub is a "mock object" a "mock object" is a stub. Stubs are used in both procedural and OO languages. —Preceding unsigned comment added by 172.206.19.160 (talkcontribs)

Despite the fact that 90% the distinction makes little difference, proponents of Extreme Programming usually assert that they are different entities, on the ground that while stubs only act as placeholders for volatile services, mock objects can also have expectations attached to them. Martin Fowler wrote a very good piece on this: http://www.martinfowler.com/articles/mocksArentStubs.htmlEdward Z. Yang(Talk) 01:31, 28 October 2006 (UTC)
Agreed. The article shouldn't say that mocks "are" stubs, but it's probably a good idea to include a section comparing them to stubs or at least mention that they're similar, instead of just having stubs in the "see also". Babomb 17:47, 28 October 2006 (UTC)

Suggestion: 'Mocking the Embbedded World' external link change?[edit]

I'd like to suggest a change to the final link in the list of external links ("Mocking the Embedded World"). I am the principal author of the original paper.

Methods & Tools Newsletter (the current destination of the link being discussed) approached me asking if they could publish the work. I agreed and provided an edited and condensed version of the original paper.

The full paper AND an executable example project can be found at another link (http://www.atomicobject.com/pages/Embedded+Software#MockingEmbeddedWorld). Perhaps this is a more useful external link; as such, I offer for consideration that the link be updated. Mkarlesky (talk) 18:24, 22 January 2008 (UTC)

Having not seen any objections, I've gone ahead and updated the 'Mocking the Embedded World' external link to the one suggested above. Mkarlesky (talk) 21:21, 29 January 2008 (UTC)