Inheriting test classes

A

aidy

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
 
S

Stefan Mahlitz

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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 ;)
end
end

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFE9rUj9S2Eui6zfdQRAtN5AKCcjVXYZeUi/Qh1iM3SOay52hLc8gCcDMgc
4FXA0QPUVqzhFVzr3C6icCY=
=arYe
-----END PGP SIGNATURE-----
 

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
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top