Modules and TestUnit

Hi all,

If I have a module, and I want to test that module’s methods
independently within TestUnit, what is the best approach?

Am I obligated to define module_function for each method so that I can
do assert_equal(“foo”,MyModule.foo)? Or am I just supposed to
"include" the module in the subclass of Test::Unit::TestCase and use
it that way?

Advice appreciated.

Dan

Am I obligated to define module_function for each method so that I can
do assert_equal(“foo”,MyModule.foo)? Or am I just supposed to
“include” the module in the subclass of Test::Unit::TestCase and use
it that way?

I’ve done the latter with much success. Unless your module modifies the
class in some way that interferes with the test case running, you
should be all good.

···


David Heinemeier Hansson,
http://www.basecamphq.com/ – Web-based Project Management
http://www.loudthinking.com/ – Broadcasting Brain

If the module does interfere with tests running, it’s pretty easy to
just do:

class ModuleContainer
include MyModule
end

def setup
@module = ModuleContainer.new
end

But including it right in the TestCase is obviously a bit simpler.

Nathaniel
Terralien, Inc.

<:((><

···

On Apr 2, 2004, at 04:53, David Heinemeier Hansson wrote:

Am I obligated to define module_function for each method so that I can
do assert_equal(“foo”,MyModule.foo)? Or am I just supposed to
“include” the module in the subclass of Test::Unit::TestCase and use
it that way?

I’ve done the latter with much success. Unless your module modifies
the class in some way that interferes with the test case running, you
should be all good.