[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Module and Test::Unit

aidy

9/27/2006 10:39:00 AM

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

3 Answers

Alex Young

9/27/2006 12:01:00 PM

0

aidy wrote:
> 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?

--
Alex

bpettichord

9/27/2006 3:56:00 PM

0

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/20...

Bret


aidy

9/28/2006 9:45:00 AM

0


bpettichord@gmail.com wrote:

> http://www.io.com/~wazmo/blog/archives/20...

Very useful blog. I'll link it from mine.

cheers

aidy