Module and Test::Unit

A

aidy

Hi,

Is there any way we can use test assertations in a module, or do we
always need to create a test class and inherit test unit?

I am using assertations for GUI tests and have modules with re-usable
methods.

thank you

aidy
 
A

Alex Young

aidy said:
Hi,

Is there any way we can use test assertations in a module, or do we
always need to create a test class and inherit test unit?

I am using assertations for GUI tests and have modules with re-usable
methods.
I'm not sure if this is what you're asking, but I do this sort of thing
quite a lot:

module ServiceTests
def test_foo
assert @thing.foo
end
def test_bar
assert @thing.bar
end
end

class RawTests < Test::Unit::TestCase
include ServiceTests
def setup
@thing = Thing.new
end
end

class XMLRPCTest < Test::Unit::TestCase
include ServiceTests
def setup
client = XMLRPC::Client.new('localhost', '/', $port)
@thing = client.proxy('thing')
end
end

That ensures that return values and the like are correct across both
native and RPC calls, without overly duplicating code. Is that what you
were after?
 
B

bpettichord

You can mix in the assertion module even if you are not using
Test::Unit::TestCase. Thus:

module mine
include Test::Unit::Assertions
def my_func
do_something
assert_equal 2, x
end
end

The only thing "wrong" with this is that your assertions won't be
counted if this module is actually, later, used by a test case. To fix
that problem, see http://www.io.com/~wazmo/blog/archives/2006_05.html

Bret
 

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,213
Messages
2,571,109
Members
47,701
Latest member
LeoraRober

Latest Threads

Top