[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Test::Unit running all tests with automated suite

Brett Schuchert

4/3/2007 1:35:00 AM

Am I missing something when using Test::Unit in Eclipse? I am used to
using JUnit and/or NUnit and being able to select a project and run all
of the tests. I don't see this feature and I suspect I'm just blind.

I've come up with the following "automated" suite script that seems to
get the job done. I had to do this in JUnit 5 years ago when the JUnit
eclipse 2.x plugin didn't support this:

require 'test/unit'
require 'find'

def allFiles
files = Array.new
Find.find('./') { |f|
if(f =~ /_test/)
f = f.sub(/\.\//, "").sub(/\.rb$/,"")
files.push(f)
end
}
files
end

allFiles().each {|f| require f}

A comment:
This is simple, I know. I only recursively find files that match
*_test.rb from the current directory then I require the files and
Test::Unit automatically generates the suite method for me. For now this
is adequate.

So two questions:

1. Is the necessary or what am I missing (I've just started using Ruby a
few days ago).
2. I assume someone can suggest to me ways to shorten this up. I'm all
ears.

Thanks!

Brett

--
Posted via http://www.ruby-....

6 Answers

Andy Morrow

4/3/2007 5:18:00 AM

0

There's an excellent article at the following URL on IBM's site
introducing the Ruby mode for Eclipse. Tthey run you through how to
set up Test::Unit run configurations. Hope this helps.
Andy Morrow

http://www-128.ibm.com/developerworks/opensource/l...
rubyeclipse/#N101D7

On Apr 2, 2007, at 6:35 PM, Brett Schuchert wrote:

> Am I missing something when using Test::Unit in Eclipse? I am used to
> using JUnit and/or NUnit and being able to select a project and run
> all
> of the tests. I don't see this feature and I suspect I'm just blind.
>
> I've come up with the following "automated" suite script that seems to
> get the job done. I had to do this in JUnit 5 years ago when the JUnit
> eclipse 2.x plugin didn't support this:
>
> require 'test/unit'
> require 'find'
>
> def allFiles
> files = Array.new
> Find.find('./') { |f|
> if(f =~ /_test/)
> f = f.sub(/\.\//, "").sub(/\.rb$/,"")
> files.push(f)
> end
> }
> files
> end
>
> allFiles().each {|f| require f}
>
> A comment:
> This is simple, I know. I only recursively find files that match
> *_test.rb from the current directory then I require the files and
> Test::Unit automatically generates the suite method for me. For now
> this
> is adequate.
>
> So two questions:
>
> 1. Is the necessary or what am I missing (I've just started using
> Ruby a
> few days ago).
> 2. I assume someone can suggest to me ways to shorten this up. I'm all
> ears.
>
> Thanks!
>
> Brett
>
> --
> Posted via http://www.ruby-....
>
>


Ryan Davis

4/3/2007 8:44:00 AM

0


On Apr 2, 2007, at 18:35 , Brett Schuchert wrote:

> Am I missing something when using Test::Unit in Eclipse? I am used to
> using JUnit and/or NUnit and being able to select a project and run
> all
> of the tests. I don't see this feature and I suspect I'm just blind.
>
> I've come up with the following "automated" suite script that seems to
> get the job done. I had to do this in JUnit 5 years ago when the JUnit
> eclipse 2.x plugin didn't support this:
>
> require 'test/unit'
> require 'find'
>
> def allFiles
> files = Array.new
> Find.find('./') { |f|
> if(f =~ /_test/)
> f = f.sub(/\.\//, "").sub(/\.rb$/,"")
> files.push(f)
> end
> }
> files
> end

As far as eclipse goes, I cannot help you. Generically, there are
many ways to go about it.

+ Use testrb:

% testrb test/**/*_test.rb
[...]
Finished in 5.562656 seconds.

297 tests, 886 assertions, 0 failures, 0 errors

+ Here is a much more concise version of what you wrote:

(%w(test/unit) + Dir['**/*_test.rb']).each { |f| require f }

+ And then there is autotest:

% autotest
# and happily leave it running all day

+ And probably many more.


Brett Schuchert

4/3/2007 1:41:00 PM

0

Andy Morrow wrote:
> There's an excellent article at the following URL on IBM's site
>
> http://www-128.ibm.com/developerworks/opensource/l...
> rubyeclipse/#N101D7
Andy,

Thanks, that is an excellent article for getting started and it's what I
started with. Unfortunately it only discusses running individual tests,
not suites of tests.

--
Posted via http://www.ruby-....

Brett Schuchert

4/3/2007 1:55:00 PM

0

Ryan Davis wrote:
> On Apr 2, 2007, at 18:35 , Brett Schuchert wrote:
>
>> require 'find'
>> end
> As far as eclipse goes, I cannot help you. Generically, there are
> many ways to go about it.

Ya, maybe I'm just an old Eclipse hack (I like using it). I even use a
VI plugin in eclipse.

>
> + Use testrb:
>
> % testrb test/**/*_test.rb

Maybe instead of using Test::Unit I should be using other testing
frameworks. Not sure. When I started using Java years ago (and C++
before that) I did pretty much work at the command line.

>
> + Here is a much more concise version of what you wrote:
>
> (%w(test/unit) + Dir['**/*_test.rb']).each { |f| require f }

Thanks, that's better. I need to update this to skip subversion meta
directories (.svn) but I'm sure I can figure that out.

> + And then there is autotest:
>
> % autotest
> # and happily leave it running all day
>
> + And probably many more.

So is there a direction in which the "ruby community" is going with
respect to unit testing and continuous integration?

--
Posted via http://www.ruby-....

Ryan Leavengood

4/3/2007 2:44:00 PM

0

On 4/2/07, Brett Schuchert <schuchert@yahoo.com> wrote:
>
> So two questions:
>
> 1. Is the necessary or what am I missing (I've just started using Ruby a
> few days ago).
> 2. I assume someone can suggest to me ways to shorten this up. I'm all
> ears.

To answer both questions:

require 'test/unit'
require 'test/unit/collector/dir'

Test::Unit::Collector::Dir.new.collect

By default this recursively collects and runs all test case classes in
the current directory in files that match the pattern test_*.rb. It is
very customizable though. For example to examine all .rb files for
tests:

dc = Test::Unit::Collector::Dir.new
dc.pattern << /\b.*\.rb\Z/m
dc.collect

Someone really needs to properly document all the cool stuff included
with Test::Unit. That someone may be me eventually :)

Ryan

Brett Schuchert

4/3/2007 5:04:00 PM

0

Ryan Leavengood wrote:
> dc = Test::Unit::Collector::Dir.new
> dc.pattern << /\b.*\.rb\Z/m
> dc.collect
>
> Someone really needs to properly document all the cool stuff included
> with Test::Unit. That someone may be me eventually :)
>
> Ryan

Even better!

Thanks Ryan, I figured I was missing something obvious. Now if someone
would update the plugin to do this!

Brett

--
Posted via http://www.ruby-....