[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

run only one test case?

Phlip

9/4/2006 8:27:00 PM

Rubies:

Here's where I run my Ruby/Unit suite:

aTestSuite = Test::Unit::TestSuite.new("MRW")
aTestSuite << a bunch of suites
got = runner.run(aTestSuite)

Now how to augment that so we fetch ARGV[], and if there's a test case by
name, only run that one case?

--
Phlip
http://c2.com/cgi/wik... <-- NOT a blog!!!


19 Answers

Paul Lutus

9/4/2006 9:08:00 PM

0

Phlip wrote:

> Rubies:
>
> Here's where I run my Ruby/Unit suite:
>
> aTestSuite = Test::Unit::TestSuite.new("MRW")
> aTestSuite << a bunch of suites
> got = runner.run(aTestSuite)
>
> Now how to augment that so we fetch ARGV[], and if there's a test case by
> name, only run that one case?

Is this what you mean?

#! /usr/bin/ruby

def exec(s)
puts "Exec #{s}"
end

if ARGV.size > 0
exec(ARGV.first)
else
exec("something else")
end

--
Paul Lutus
http://www.ara...

Phlip

9/4/2006 10:02:00 PM

0

Paul Lutus wrote:

> Is this what you mean?

No, and I don't see any connection between it and my question.

--
Phlip
http://c2.com/cgi/wik... <-- NOT a blog!!!


Phlip

9/4/2006 10:05:00 PM

0

> Paul Lutus wrote:
>
>> Is this what you mean?
>
> No, and I don't see any connection between it and my question.

Sorry - one connection: ARGV.shift. I know _that_!!

> --
> Phlip
> http://c2.com/cgi/wik... <-- NOT a blog!!!
>


William Crawford

9/4/2006 10:05:00 PM

0

Paul Lutus wrote:
> Phlip wrote:
>
>> Rubies:
>>
>> Here's where I run my Ruby/Unit suite:
>>
>> aTestSuite = Test::Unit::TestSuite.new("MRW")
>> aTestSuite << a bunch of suites
>> got = runner.run(aTestSuite)
>>
>> Now how to augment that so we fetch ARGV[], and if there's a test case by
>> name, only run that one case?
>
> Is this what you mean?
>
> #! /usr/bin/ruby
>
> def exec(s)
> puts "Exec #{s}"
> end
>
> if ARGV.size > 0
> exec(ARGV.first)
> else
> exec("something else")
> end

Combine that with
Test::Unit::UI::Console::TestRunner.run(TS_MyTests)
From
http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test...
And I think you can do what you want.

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

Phlip

9/4/2006 10:40:00 PM

0

> Here's where I run my Ruby/Unit suite:
>
> aTestSuite = Test::Unit::TestSuite.new("MRW")
> aTestSuite << a bunch of suites
> got = runner.run(aTestSuite)

The above code runs all test cases. I want to run only one of them.

> Now how to augment that so we fetch ARGV[], and if there's a test case by
> name, only run that one case?

Suppose one of them is called test_readMyPost. Can I run it like this?

got = runner.run(aTestSuite, 'test_readMyPost')

Alternately, could I loop thru aTestSuite's cases, find it, and run it?

(I'm not asking how to run test suites, or how to parse command line
arguments here!)

--
Phlip
http://c2.com/cgi/wik... <-- NOT a blog!!!


Paul Lutus

9/4/2006 11:07:00 PM

0

Phlip wrote:

> Paul Lutus wrote:
>
>> Is this what you mean?
>
> No, and I don't see any connection between it and my question.

Here's your question:

> Now how to augment that so we fetch ARGV[], and if there's a test case by
> name, only run that one case?

My reply shows how to fetch ARGV, and if there's a test case specified, use
that instead of a predefined name.

Maybe you should express yourself more clearly.

--
Paul Lutus
http://www.ara...

Phlip

9/4/2006 11:16:00 PM

0

Paul Lutus wrote:

> My reply shows how to fetch ARGV, and if there's a test case specified,
> use
> that instead of a predefined name.

Your code:

#! /usr/bin/ruby

def exec(s)
puts "Exec #{s}"
end

if ARGV.size > 0
exec(ARGV.first)
else
exec("something else")
end

I don't see it applying s to the test cases. It just prints out the name,
and I can't believe you actually think this answers my question. Maybe you
need to read more carefully.

--
Phlip
http://c2.com/cgi/wik... <-- NOT a blog!!!


Logan Capaldo

9/4/2006 11:28:00 PM

0


On Sep 4, 2006, at 4:30 PM, Phlip wrote:

> Rubies:
>
> Here's where I run my Ruby/Unit suite:
>
> aTestSuite = Test::Unit::TestSuite.new("MRW")
> aTestSuite << a bunch of suites
> got = runner.run(aTestSuite)
>
> Now how to augment that so we fetch ARGV[], and if there's a test
> case by
> name, only run that one case?
>

if ARGV[0]
system("ruby tc_#{ARGV[0]}.rb")
end


> --
> Phlip
> http://c2.com/cgi/wik... <-- NOT a blog!!!
>
>
>


dblack

9/4/2006 11:35:00 PM

0

Phlip

9/5/2006 1:23:00 AM

0

Rubies:

Here's a normal example of running a Ruby/Unit suite:

aTestSuite = Test::Unit::TestSuite.new("MRW")
aTestSuite << a bunch of suites
got = runner.run(aTestSuite)

The above code runs all test cases. I want to run only one of them.

A "test suite" is (generally) a list of test cases. Here, it is a list of
lists of test cases. Running only one *.rb file would run all cases in that
file's suites. I want to run only one test case. Here are three test cases:

class SomeSuite < Test::Unit::TestCase

def test_runThisCase()
#...
end


def test_dontRunThis()
#...
end

def test_orThis()
#...
end

end

Running SomeSuite is trivial.

Now how to augment that so if a caller has supplied one case name (perhaps
via command line arguments and ARGV[]), and then only run that one case?

Suppose I only want to run test_runThisCase. If I had invented Ruby/Unit, we
could run it like this:

got = runner.run(aTestSuite, 'test_readMyPost')

Unfortunately, the test.rb files (like many Ruby library files) are
write-only, and I generally can't read them well enough to understand how to
apply that syntax. Is such a feature available through these objects?

Alternately, could I loop thru aTestSuite's cases, find it, and run it?

(I'm not asking how to run test suites, or how to parse command line
arguments here!)

--
Phlip
http://c2.com/cgi/wik... <-- NOT a blog!!!