# How to test a ruby class

**URL:** <https://www.ruby-forum.com/t/how-to-test-a-ruby-class/65519>\
**Category:** Ruby\
**Created:** [February 10, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/how-to-test-a-ruby-class/65519 "2006-02-10T20:08:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/how-to-test-a-ruby-class/65519/1 "2006-02-10T20:08:32Z")

</div>

> Hi: I just installed Ruby and have FreeRIDE open. In Ruby, is there a  
> method comparable to the “main” method in java that will run the class for  
> testing?  
> I would like to run my class from the IDE.
> 
> Thanks,  
> Doug

E-MAIL CONFIDENTIALITY NOTICE:  
The contents of this e-mail message and any attachments are intended  
solely  
for the addressee(s) and may contain confidential and/or legally  
privileged  
information. If you are not the intended recipient of this message or  
if  
this message has been addressed to you in error, please immediately  
alert  
the sender by reply e-mail and then delete this message and any  
attachments.  
If you are not the intended recipient, you are notified that any use,  
dissemination, distribution, copying, or storage of this message or any  
attachments is strictly prohibited.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2006, 8:44pm UTC](https://www.ruby-forum.com/t/how-to-test-a-ruby-class/65519/2 "2006-02-10T20:44:41Z")

</div>

On Feb 10, 2006, at 2:08 PM, removed\_email\_address@domain.invalid wrote:

> > Hi: I just installed Ruby and have FreeRIDE open. In Ruby, is  
> > there a  
> > method comparable to the “main” method in java that will run the  
> > class for  
> > testing?  
> > I would like to run my class from the IDE.

An alternative to ad-hoc testing in an IDE or via the command line is  
using independent, repeatable tests, i.e., unit testing. Mike C.  
has a good, brief introduction to unit tests as learning tests here:  
[http://www.clarkware.com/cgi/blosxom/2005/03/18](http://www.clarkware.com/cgi/blosxom/2005/03/18). Also, you can find  
the docs for Test::Unit, Ruby’s built-in unit testing framework,  
here: [http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/](http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/)  
Test/Unit.html.

Regards,  
Craig

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 10, 2006, 8:47pm UTC](https://www.ruby-forum.com/t/how-to-test-a-ruby-class/65519/3 "2006-02-10T20:47:26Z")

</div>

DÅ?a Piatok 10 FebruÃ¡r 2006 20:08 removed\_email\_address@domain.invalid napÃ­sal:

> > Hi: I just installed Ruby and have FreeRIDE open. In Ruby, is there a  
> > method comparable to the “main” method in java that will run the class  
> > for testing?  
> > I would like to run my class from the IDE.
> > 
> > Thanks,  
> > Doug

My two cents follow: I can’t stand the very sight of people making a  
script or  
class executable for the sake of testing - main() methods and the like  
are  
supposed to execute a standalone program, and that’s that. If you want  
to  
test, then do it properly, create a separate hierarchy of files with  
unit  
tests. It’s just as easy, if not easier to write, and you don’t clutter  
your  
business logic with test code.

David V.
