# Unit testing questions

**URL:** <https://www.ruby-forum.com/t/unit-testing-questions/73738>\
**Category:** Ruby\
**Created:** [October 26, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/unit-testing-questions/73738 "2006-10-26T19:40:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrickharlan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@patrickharlan](https://www.ruby-forum.com/u/patrickharlan)\
**Post date:** [October 26, 2006, 7:40pm UTC](https://www.ruby-forum.com/t/unit-testing-questions/73738/1 "2006-10-26T19:40:30Z")

</div>

I have been working on a msg4r wrapper that provides a number of  
messaging clients (i.e. Websphere MQ, ActiveMQ, Stomp) to ruby all  
with that same API. I have some simple unit tests in place that  
require the actual messaging systems to be available - this mean that  
there is significant work required to setup the test, but when they  
run I know that they are actually working. I am considering some sort  
of mock approach, but I fear that I will be missing out on testing the  
specifics of the wire protocols, timing etc.

I am not sure if there is a “right” answer, but I was wondering if  
there were any ideas/hints other developers might have.

Thanks  
pth

---

<div class="post-metadata">

**Author:** ![patrickharlan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@patrickharlan](https://www.ruby-forum.com/u/patrickharlan)\
**Post date:** [October 26, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/unit-testing-questions/73738/2 "2006-10-26T20:20:34Z")

</div>

On 10/26/06, Patrick H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> there were any ideas/hints other developers might have.

If you have tests that work, why change them?

Here are my reasons for using mock objects:

1. fixture is too complex to configure for unit testing
2. you do not have control over the entire system (i.e. talking to a  
remote web service)
3. you are controlling an external device that could be damaged

Mock objects are great, but they require work to maintain. If you can  
test without them, great! One less thing to modify when the system  
needs to change.

If you are constrained by 1, 2, or 3, then you cannot live without mock  
objects.

I’ve used Jim W.'s FlexMock, and I’d highly recommend it. A  
fellow rubyist has recommended MockFS for mocking out the entire file  
system.

Blessings,  
TwP

[http://onestepback.org/software/flexmock/](http://onestepback.org/software/flexmock/)  
[http://rubyforge.org/projects/mockfs/](http://rubyforge.org/projects/mockfs/)
