Inheriting test classes

Discussion in 'Ruby' started by aidy, Aug 31, 2006.

  1. aidy

    aidy Guest

    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, Aug 31, 2006
    #1
    1. Advertising

  2. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    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 ;)
    end
    end

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

    iD8DBQFE9rUj9S2Eui6zfdQRAtN5AKCcjVXYZeUi/Qh1iM3SOay52hLc8gCcDMgc
    4FXA0QPUVqzhFVzr3C6icCY=
    =arYe
    -----END PGP SIGNATURE-----
     
    Stefan Mahlitz, Aug 31, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anthony Williams
    Replies:
    8
    Views:
    566
    Anthony Williams
    Feb 24, 2004
  2. Chris Foster
    Replies:
    2
    Views:
    386
    Chris Foster
    Aug 23, 2004
  3. Joseph Paterson
    Replies:
    2
    Views:
    266
    terminator
    Jul 27, 2007
  4. Martin
    Replies:
    3
    Views:
    665
    Victor Bazarov
    Jan 21, 2008
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    709
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page