how do I create a TestSuite

R

Rasputin

This code used to work under 1.6.8 with Test::Unit 0.1.8:

0rasputin@lb:stickyfingers$ cat test/all.rb
#! /usr/local/bin/ruby -w

require 'test/unit'

require 'test/chaintest'
require 'test/chunkertest'
require 'test/filestoretest'

class Daddy < Test::Unit::TestSuite
self << ChainTest.new
self << ChunkerTest.new
self << FilestoreTest.new
end

0rasputin@lb:stickyfingers$

(The classes listed are just bog standard
class ChunkerTest < Test::Unit::TestCase' affairs).

It now gives errors under CVS Ruby - looks like a change in the TestCase
constructor. How do I create a testsuite now?


0rasputin@lb:stickyfingers$ /usr/local/bin/ruby -v
ruby 1.8.1 (2003-11-21) [i386-netbsdelf]
0rasputin@lb:stickyfingers$ /usr/local/bin/ruby test/all.rb
test/all.rb:10:in `initialize': wrong number of arguments(0 for 1) (ArgumentError)
from test/all.rb:10:in `new'
from test/all.rb:10
 
N

Nathaniel Talbott

This code used to work under 1.6.8 with Test::Unit 0.1.8:

Are you sure? I don't think creating a TestCase without a test to run
has ever worked. I think what you want is:

0rasputin@lb:stickyfingers$ cat test/all.rb
#! /usr/local/bin/ruby -w

require 'test/unit'

require 'test/chaintest'
require 'test/chunkertest'
require 'test/filestoretest'

class Daddy < Test::Unit::TestSuite
self << ChainTest.new
self << ChunkerTest.new
self << FilestoreTest.new
self << ChainTest.suite
self << ChunkerTest.suite
self << FilestoreTest.suite
end

It now gives errors under CVS Ruby - looks like a change in the
TestCase
constructor. How do I create a testsuite now?

As I said, I don't think the code above would have ever worked. You
might like to know, though, that you don't have to create your own
TestSuite; try this:

#! /usr/local/bin/ruby -w

require 'test/unit'

require 'test/chaintest'
require 'test/chunkertest'
require 'test/filestoretest'

I think you'll find that's all you need.

HTH,


Nathaniel

<:((><
 
R

Rasputin

* Nathaniel Talbott said:
Are you sure? I don't think creating a TestCase without a test to run
has ever worked. I think what you want is:

Hmm,looks like you might be right. It definitely worked with no
errors last week, possibly under the CVS code?
self << ChainTest.suite
self << ChunkerTest.suite
self << FilestoreTest.suite

As I said, I don't think the code above would have ever worked.

God knows where I got that from then! I cut and pasted from somewhere...
might like to know, though, that you don't have to create your own
TestSuite; try this:

#! /usr/local/bin/ruby -w

require 'test/unit'

require 'test/chaintest'
require 'test/chunkertest'
require 'test/filestoretest'

Thats great , thanks.
 
S

Simon Strandgaard

* Nathaniel Talbott said:
This code used to work under 1.6.8 with Test::Unit 0.1.8: [snip]
class Daddy < Test::Unit::TestSuite
self << ChainTest.new
self << ChunkerTest.new
self << FilestoreTest.new
self << ChainTest.suite
self << ChunkerTest.suite
self << FilestoreTest.suite


How about a 'test_all.rb' which simply just appends all testsuites it
finds in current dir ?


server> expand -t2 test_all.rb
require 'test/unit'

class TestAll
def TestAll.suite
suite = Test::Unit::TestSuite.new
Object.constants.sort.each do |k|
next if /^Test/ !~ k
constant = Object.const_get(k)
if constant.kind_of?(Class) &&
constant.superclass == Test::Unit::TestCase
suite << constant.suite
end
end
suite
end
end

if __FILE__ == $0
Dir.glob("test_*.rb").each do |file|
require "#{file}"
end
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TestAll)
end
server>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,816
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top