Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Create dynamic tests for Test::Unit

Reply
Thread Tools

Create dynamic tests for Test::Unit

 
 
Achim Domma (SyynX Solutions GmbH)
Guest
Posts: n/a
 
      11-20-2005
Hi,

I have some experiences in generic programming in python and .Net but
I'm quite new to ruby. I want to test a web app using watir. There are
many forms with similar structure which have to be filled with data. So
my idea was to create a YAML file which holds the location of a form,
the type of the form and the data to be filled in.

My problem is, that I don't see on how to create dynamicaly a single
test for each entry in the yaml file!? Am I not yet thinking in ruby?
Could somebody guide me to the right direction on how to solve this task?

regards,
Achim
 
Reply With Quote
 
 
 
 
Pit Capitain
Guest
Posts: n/a
 
      11-20-2005
Achim Domma (SyynX Solutions GmbH) schrieb:
> I have some experiences in generic programming in python and .Net but
> I'm quite new to ruby. I want to test a web app using watir. There are
> many forms with similar structure which have to be filled with data. So
> my idea was to create a YAML file which holds the location of a form,
> the type of the form and the data to be filled in.
>
> My problem is, that I don't see on how to create dynamicaly a single
> test for each entry in the yaml file!? Am I not yet thinking in ruby?
> Could somebody guide me to the right direction on how to solve this task?


Hallo Achim,

maybe this example gets you going:

require "test/unit"

DynamicTest = Struct.new :name, :expected, :actual

DYNAMIC_TESTS = [
DynamicTest.new( "test_one", 123, 123 ),
DynamicTest.new( "test_two", 125, 123 ),
DynamicTest.new( "test_three", 127, 127 ),
]

Class.new Test::Unit::TestCase do
DYNAMIC_TESTS.each do |t|
define_method t.name do
assert_equal t.expected, t.actual
end
end
end

Running this, I get

Loaded suite C:/tmp/r
Started
..F
Finished in 0.047 seconds.

1) Failure:
test_two()
[C:/tmp/r.rb:15:in `test_two'
C:/tmp/r.rb:14:in `test_two']:
<125> expected but was
<123>.

3 tests, 3 assertions, 1 failures, 0 errors

Regards,
Pit


 
Reply With Quote
 
 
 
 
Achim Domma (SyynX Solutions GmbH)
Guest
Posts: n/a
 
      11-21-2005
Pit Capitain wrote:

> maybe this example gets you going:


Thanks, that's what I was looking for. Seems like I have to learn much
more ruby!

regards,
Achim
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Junit tests, setting up tests without having to create a billion methods xyzzy12@hotmail.com Java 8 02-28-2006 08:59 PM
Tests without study guides or practice tests? =?Utf-8?B?Q2hyaXNS?= Microsoft Certification 8 12-20-2005 04:59 AM
Constant.t fails 240 of 272 tests and recurs.t fails 1 of 25 tests on HPUX using perl 5.8.7 dayo Perl Misc 11 12-16-2005 09:09 PM
Press Release - Visual CertExam Suite Makes It Easy to Create and Take Professional Practice Tests David Johnson MCSE 2 10-20-2004 02:44 AM
Press Release - Visual CertExam Suite Makes It Easy to Create and Take Professional Practice Tests David Johnson MCSD 0 10-19-2004 04:02 PM



Advertisments