Inheriting test classes

Hi,

All my GUI test classes contain this code within the constructor.

class ST_MSE_33
  def initialize

    start_browser
    login

   ................

    rescue => e
     p "test failed: #{e.message}"
     p e.backtrace
    ensure
     log_out
     close_window
  end
end

That is, there is always the same start and same end, but a different
middle.
Is there any way I could use inheritance to avoid duplication?

Thank You

Aidy

aidy wrote:

Hi,

All my GUI test classes contain this code within the constructor.

class ST_MSE_33
  def initialize

    start_browser
    login

   ................

    rescue => e
     p "test failed: #{e.message}"
     p e.backtrace
    ensure
     log_out
     close_window
  end
end

That is, there is always the same start and same end, but a different
middle.
Is there any way I could use inheritance to avoid duplication?

I would use the following construct:

class GeneralBehaviour
  def initialize
    start_browser
    login

    specific_behaviour

    ...
  end

  # this is only necessary if GeneralBehaviour can be used
  # on its own
  def specific_behaviour
  end
end

class SpecifB1 < GeneralBehaviour
  def specific_behaviour
    # do sth specific :wink:
  end
end