[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Trouble with executing discrete testcase functions within a Test::Unit::TestCase class

Pit Capitain

1/10/2007 1:58:00 PM

Kp schrieb:
> (...)
> The model I'm using is briefly detailed below...
>
> a. A QtRuby application reads from the .rb file and parses for all 'def's
> that exist within the file
> b. Users can use the QtRuby app to create testcases (comprised of a
> selection of the functions in the ruby file, with custom parameters entered
> in the QtRuby app for each function)
> c. These testcases can then be combined in the app to form suites that can
> be executed.
> (...)

I'm not sure I understand what you want. Since test methods have no
parameters, they can't be the "functions" you are talking about. So,
what are those functions doing? Who calls the actual test methods?

Regards,
Pit

1 Answer

Pit Capitain

1/11/2007 8:41:00 AM

0

Kp schrieb:
> Yes, the 'functions' I'm talking about are not the functions that will
> automatically be executed, and their names don't start with 'test...'.
>
> But since they are within the Test::Unit:TestCase class, they have
> access to
> methods such as 'assert' etc.
>
> What I need is a way to access and run these functions from an external
> program (a different .rb file). I don't want these functions to be run
> automatically as unit-testing tests, as I'm using them to test
> functionality
> of a web-based app using the Selenium-RC tool.
>
> Hope I was clearer here... much thanks for your reply.

Kp, why do you put your methods in a subclass of Test::Unit::TestCase?
If all you need are the assertion methods you can do something like this:

require "test/unit/assertions"

class C
include Test::Unit::Assertions
def check_successor a, b
assert_equal a, b.succ
end
end

c = C.new
c.check_successor 2, 1
c.check_successor 3, 1 rescue puts $!

# => <3> expected but was
# => <2>.

This way the automatic test runner of test/unit isn't run.

If you have problems calling those methods "from an external program",
maybe you should look at the #send method. Continuing the code above:

methods_to_run_with_args = [
[ "check_successor", "b", "a" ],
[ "check_successor", "c", "a" ],
[ "check_successor", 3, 2 ],
[ "check_successor", 4, 2 ],
]

methods_to_run_with_args.each do |name, *args|
begin
print "running #{name} with #{args.inspect}: "
c.send name, *args # <<< here is c.send
rescue Test::Unit::AssertionFailedError
puts "failed"
rescue Exception
puts "error"
else
puts "ok"
end
end

# => running check_successor with ["b", "a"]: ok
# => running check_successor with ["c", "a"]: failed
# => running check_successor with [3, 2]: ok
# => running check_successor with [4, 2]: failed

Sorry if I told you things you already know. Feel free to ask again if
this doesn't answer your question.

Regards,
Pit