Create dynamic tests for Test::Unit

  • Thread starter Achim Domma (SyynX Solutions GmbH)
  • Start date
A

Achim Domma (SyynX Solutions GmbH)

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
 
P

Pit Capitain

Achim said:
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
 
A

Achim Domma (SyynX Solutions GmbH)

Pit said:
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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top