other way to send message to parent class in unit testing

A

akbarhome

Hi, I have 8 class that need to be tested. They all have some same
method to be tested. So I make parent class to do the duplicate work.

This is the parent class:

class BaseElementControllerTest < Test::Unit::TestCase

def setup
# notice this line
@controller = @con_name.new
# end of notice this line

@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end

def test_new
get :new
assert_response :success
end

end

The 8 class have same method that need to be tested, that is test_new.
The child class is like this:

require File.dirname(__FILE__) + '/../test_helper'
require 'thermo_detector_controller'

# Re-raise errors caught by the controller.
class ThermoDetectorController; def rescue_action(e) raise e end; end

# notice this line
@con_name = ThermoDetectorController
# end of notice this line

class ThermoDetectorControllerTest < BaseElementControllerTest
fixtures :thermo_detector_order_letters, :workers

# specific method to be tested
....
end

Another child class:

require File.dirname(__FILE__) + '/../test_helper'
require 'quartz_heater_controller'

# Re-raise errors caught by the controller.
class QuartzHeaterController; def rescue_action(e) raise e end; end

# notice this line
@con_name = QuartzHeaterController
# end of notice this line

class QuartzHeaterControllerTest < BaseElementControllerTest
fixtures :quartz_heater_order_letters, :workers

# specific method to be tested
....
end

In this case, I send message to parent class using @con_name variable,
instantiated before child class definition. I have to send message
because in parent class, @controller variable must be instantiated
according to child class. So I wonder if there is another way to send
message to parent in unit testing? I try to use initialize method, but
unit testing "forbid" it. Or this is the only way to send message to
parent class in unit testing?

Thank you.
 
A

akbarhome

Edit message:
My mistake. @con_name should be $con_name and you can put $con_name in
child class definition
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top