[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

using unit test

Brad Tilley

3/24/2006 1:24:00 AM

What is the most prevalent way of using unit testing in Ruby? Do I
require 'test/unit' and add test methods to production scripts and then
comment the testing portions out when not testing? Or, should I develop
a 'testing' version of the scripts identical to the production versions?

Thanks for any advice. I've got the concept down... just thinking about
implementation and actively using tests.

Brad
4 Answers

Tim Hunter

3/24/2006 1:38:00 AM

0

rtilley wrote:
> What is the most prevalent way of using unit testing in Ruby? Do I
> require 'test/unit' and add test methods to production scripts and then
> comment the testing portions out when not testing? Or, should I develop
> a 'testing' version of the scripts identical to the production versions?
>
> Thanks for any advice. I've got the concept down... just thinking about
> implementation and actively using tests.
>
> Brad

Put the tests in a separate directory alongside the code. Chapter 12 of
the Pickaxe includes some "best practices" for unit testing Ruby with
Test::Unit.

Joe Van Dyk

3/24/2006 1:39:00 AM

0

On 3/23/06, rtilley <rtilley@vt.edu> wrote:
> What is the most prevalent way of using unit testing in Ruby? Do I
> require 'test/unit' and add test methods to production scripts and then
> comment the testing portions out when not testing? Or, should I develop
> a 'testing' version of the scripts identical to the production versions?
>
> Thanks for any advice. I've got the concept down... just thinking about
> implementation and actively using tests.

I generally put my tests in a separate tests directory from my code.
Then I have a 'run_tests.rb' file that runs all the tests. Here's the
entirety of run_tests.rb:

Dir["tests/*"].each { |f| require f }

Or, you could somehow use Rake to run the tests, like Rails does.

Joe


Eric Hodel

3/24/2006 1:50:00 AM

0

On Mar 23, 2006, at 5:38 PM, Joe Van Dyk wrote:

> On 3/23/06, rtilley <rtilley@vt.edu> wrote:
>> What is the most prevalent way of using unit testing in Ruby? Do I
>> require 'test/unit' and add test methods to production scripts and
>> then
>> comment the testing portions out when not testing? Or, should I
>> develop
>> a 'testing' version of the scripts identical to the production
>> versions?
>>
>> Thanks for any advice. I've got the concept down... just thinking
>> about
>> implementation and actively using tests.
>
> I generally put my tests in a separate tests directory from my code.
> Then I have a 'run_tests.rb' file that runs all the tests. Here's the
> entirety of run_tests.rb:
>
> Dir["tests/*"].each { |f| require f }
>
> Or, you could somehow use Rake to run the tests, like Rails does.

Even easier:

$ ls
test/
$ ls test
test_something.rb
$ testrb test
Loaded suite test
Started

Erik Hollensbe

3/28/2006 11:28:00 PM

0

On 2006-03-23 17:38:03 -0800, Tim Hunter <cyclists@nc.rr.com> said:

> rtilley wrote:
>> What is the most prevalent way of using unit testing in Ruby? Do I
>> require 'test/unit' and add test methods to production scripts and then
>> comment the testing portions out when not testing? Or, should I develop
>> a 'testing' version of the scripts identical to the production versions?
>>
>> Thanks for any advice. I've got the concept down... just thinking about
>> implementation and actively using tests.
>>
>> Brad
>
> Put the tests in a separate directory alongside the code. Chapter 12 of
> the Pickaxe includes some "best practices" for unit testing Ruby with
> Test::Unit.

I have a patch which fixes the test functionality in Minero Aoki's
setup.rb, which lets you create a test/ directory and run:

ruby setup.rb test

and it will execute all the tests in the test/ directory.

Please email privately if you want the patch (I've already submitted it
and recieved no response).